Start on a randomly choosen panorama

  • Hello everybody,

    I'm sure it's possible, and that it's tricky, but I don't manage to get out of this by myself....

    One of my client want thats every time the virtual visit start it start on a different room. There is 5 room.
    In the main xml there is the 5 loading actions, just need to pick one randomly.

    Cheers,
    David

  • Yes I have see this, but I am more looking for an "action only" solution. The external javascript is not a solution for me.
    There is some math fonction already implemented in the krPano API, perhaps a random could be added, or a complete math class, used like it for example :set(hasard, maths.random(5);); should affect a value between 1 to 5 to the "hasard" variable...

    I know that this is already included in javascript but it's more clean (in my mind at least) if we don't mix the langage.

    If the problem is about the krpano weight, perhaps a library approach could be a solution

    Bye

  • Hi,

    There is some math fonction already implemented in the krPano API, perhaps a random could be added, or a complete math class, used like it for example :set(hasard, maths.random(5);); should affect a value between 1 to 5 to the "hasard" variable...

    when you use the krpano.swf from the 1.0.8 beta 9 tools package - there is already a global "random" variable,
    it returns a random value between 0.0 and 1.0,

    e.g. to get a random value between 0 and 10 use the 'mul' action and then the 'roundval' action to remove any decimal places:

    Code
    mul(randomvalue, random, 10);
    roundval(randomvalue,0);
    trace('randomvalue=', randomvalue);

    best regards,
    Klaus

  • Hi Klaus,
    I have a problem with the random number i create using the global "random" variable. My problem is that it's a number, *smile* .
    And as a number when I try to concatenate it in a string, it add the name of the variable.

    For exemple, here is the code :

    and here is the trace :

    Quote

    INFO: krpano 1.0.8 beta 9 (build 2010-01-19)
    INFO: Flashplayer LNX 10,0,32,18 PlugIn
    INFO: registered to: David SEGUIN
    INFO: randomvalue=1
    INFO: randomvalue by get=1
    ERROR: loadscene() - scene "panorandomvalue" not found

    So I managed to do what I need with the if() but I have to write each loader, this could be more efficient if we can have a "toString" method in krPano.


    Thanks a lot,

    David

  • Hi David,

    Here a modified code:

    Code
    <plugin name="hasard"/>
     <action name="onstart">
     mul(randomvalue, random, 10);
     roundval(randomvalue,0);
     set(plugin[hasard].numero,get(randomvalue));
     trace('randomvalue=', randomvalue);
     trace('randomvalue by get=', get(plugin[hasard].numero));
     txtadd(plugin[hasard].action, 'loadscene(pano',  get(plugin[hasard].numero),', null, MERGE)');
     call(plugin[hasard].action);
     </action>


    note line 5 ---- set(plugin[hasard].numero,get(randomvalue));

    I have also some troubles using variables... it is not clear in my head how to use them... Sometimes direct variable name is enough and sometimes get() is needed... also the use of params is not always clear to me... The way I do is trying... *rolleyes*

    SAlut.

  • Thanks Michel, but this part of the code was working properly....
    The problem is here :

    txtadd(plugin[hasard].action, 'loadscene(pano', get(plugin[hasard].numero),', null, MERGE)');

    I can not pass a number as a character,krPano try to load "panorandomvalue". Normally in other langage with use a command named toString, who convert a number to a character.

    Like I said I have resolved the problem by an other way, just asking a toString function for the next version.

    Perhaps there is already one, for 2 months every time I ask for a new function, it was allready inside, but Klaus didn't speak of it. I'm sure the next released will very complete. And hopefully we will have a codex like this one for spip : http://www.spip.net/@ very very usefull for develloppers.

    I'am sure that somes of the community would be agree to help the redaction of it. For me if need I'm in.

    Good day.
    David

  • Hé bé la, Michel, ça me troue le c*l.

    On va pas traduire....

    Il y a, à peu près 0g de logique dans ça... Mais cool ça marche.

    Thanks a lot.

    Sorry for speaking french, by the way it's better not to translate this... *unsure*

    Code is poetry, some times it's difficult to understand "poetry"...

    Bye
    David

  • My working solution for randomly access of different panoramas.
    there are 3 panos :

    with this rounded-random method you obtain 1/6 times 0; 1/3 times 1; 1/3 times 2; 1/6 times 3
    it's why i affect pano3 to value=0 and =3.

    Hope it' could help others

    David

  • Code is poetry, some times it's difficult to understand "poetry"...

    Beautiful... *cool*

    Il y a, à peu près 0g de logique dans ça...

    I think there is some logic inside... *smile*

    set(plugin[hasard].numero,randomvalue);
    is like :
    plugin[hasard].numero = randomvalue ---- (the name of the variable in this case)

    set(plugin[hasard].numero,get(randomvalue));

    is like:
    plugin[hasard].numero = 3 ---- (the value of the variable in this case)

    so:
    txtadd(plugin[hasard].action, 'loadscene(pano', get(plugin[hasard].numero),', null, MERGE)');
    returns: loadscene(panorandomvalue, null, MERGE) ---- (using the first example above)
    returns: loadscene(pano3, null, MERGE) ---- (using the second example above)

    One note: randomvalue can have a value of 0... so you can have loadscene(pano0, null, MERGE) as a possible scene name ....

    SAlut.

    Edited once, last by michel (February 2, 2010 at 5:29 PM).

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!