Random Function No Way Random

TheTTheT Member Posts: 80
edited November -1 in Working with GS (Mac)
Hi,
I'm running into a problem with the game's random function. I'm spawning actors to the left and the right of the screen with a random every Timer. However as soon as the game starts, the actors show up always in the same patterns, so there it is no way a random function. I also ran into that problem on other instances.
I also tried to make a variable(or attribute if you like so), put there the timer's random time (instead of in the timer field a random() ) in and always update it in the timer function.
Hope you can help me cause this is really freaking me out and my game sorta of really depends on it.
Thanks !

Comments

  • TheTTheT Member Posts: 80
    For better understanding, check this:
    http://img21.imageshack.us/i/screenu.tif/
  • jhaasjhaas Member Posts: 233
  • TheTTheT Member Posts: 80
    Fine, but this is on the "device", I'm talking about the actual web preview ...
    Any real statements, maybe from the side of the developers ?
  • TheTTheT Member Posts: 80
    Well, thanks for your reply tshirt, but I really would like to get a reply from some of the offical guys like codemonkey ! Remember: This is not on the IPhone but on the actual Game Preview !
    Thanks !
  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    I thought my ears were burning. Maybe its just swine flu.

    The random function is not entirely random. Sometimes I get randomness if I do something like setting an attribute to some random number and displaying that attribute and I don't get a pattern.

    And for the Timer behavior, when you use the expression editor it takes the value in it when it is activated. You must deactivate it and reactivate it to take a new value. http://gamesalad.com/wiki/how_tos:gsc_variable_timer_speed
  • TheTTheT Member Posts: 80
    What the heck guys ?
    A random function that's not entirely random ? And a timer you need to reset doing code snippets ? These are really design flaws that can drive people nuts. You should really either tell people that or redesign the timer/random functions ...
    Hope you guys do some bugfixing there, it are escpeally the codes that are hidden by a gui language and that you can't see and if you don't know these tricks, get you started.
    So thx anyway, at least I guess ;)
  • adent42adent42 Key Master, Head Chef, Executive Chef, Member, PRO Posts: 3,184
    I'm on the web side of GameSalad, so I haven't peeked under then engine hood in a while, but I believe I know what is happening.

    As with most computer random number generators, this one is really pseudo-random (the sequence is random, but it's repeatable based on an initial seed value). For more info than you can shake a stick at look here: http://en.wikipedia.org/wiki/Pseudorandom_number_generator

    Jhaas has found a nice solution to this problem, basically taking user input and using it to seed the random number generator (choosing a variable spot in the sequence to start, effectively making it random). I'd suggest you try this tact if you can't wait for a fix.

    Now, the reason we've had trouble consistently recreating this problem, is that we rarely restart the whole environment when doing a slew of test (like you would by stopping and starting an iphone game). It's also hard to test in the browser, because the random number state last as long as the browser is open. I have to close Safari completely and re-open it to see the same sequence again.

    We'll be looking at the best way to solve this problem (as sometimes, having a deterministic "random" sequence can be useful). I hope this helps you better understand the source of your repetitive randomness!
  • ktfrightktfright Member Posts: 964
    I thought this we fixed, but when I try to spawn an actor, it is still not random. For me random does not work when trying to spawn. any tips?
  • beaudoin_nbeaudoin_n Member Posts: 184
    Ok,

    this doesn't work for me either.. not even to spawn just create a random value in an attribute and then displaying in an object :(

    Any workarounds ?

    I have 3 game attributes (1,2 and 3) and i tried just random, and also using random(game.time,game.time+x)-game.time

    doesn't help
    if when i start i have numbers 5 4 8
    i'll have this until i stop gamesalad and restart
  • JGary321JGary321 Member Posts: 1,246
    Did some testing on this. It goes beyond random not being random. This is what I did...

    I have an actor that rolls a random number every 1 sec. It stores it in a game.random roll attribute.

    I have another actor that just displays game.random roll. It displays fine. It updates fine. Every 1 sec it shows a new number.

    I have an actor that spawns on the scene & pulls the random number & uses it in a math equation.

    The thing is even though the text changes correctly the SAME number is used over & over in the math equation. So even though it SHOULD pull a new random number every time it pulls the random # 1 time & uses it every time after that.

    I SPAWN this actor when I need it so it should definitely update the random number. I even threw a text attribute onto the actor in question (not under ANY rules) & it NEVER updates on this actor, yet it updates on my static actor. Hopefully this will help the devs figure this out.

    EDIT: After further testing I figured out that the number does indeed update, BUT there is a bug when displaying it. For some reason it does not update the random number while displaying it as text. If the actor is persistent it will update. But if you spawn say an actor that shows the attribute it keeps the old attribute & never updates to the new attribute.
  • rebumprebump Member Posts: 1,058
    Possibly related to all this:

    I get the feeling that some of the actor's rules/behaviors value(s) get cached the first time through and re-used each time through (while others don't and shouldn't as expected)!?!?

    I say this because I have a Player actor and an Enemy actor, each with a firing delay attribute unique to them. In the Enemy, who continually fires, I use an "Every X Seconds" rule to initiate the auto-firing replacing the "X" with the firing delay attribute. It works...sort of. The firing does repeat as it should. However, with each hit the Player enacts on the Enemy actor, I decrement the Enemy's hit points (which works) and in the same area, I decrement the Enemy firing delay attribute a little to speed up the Enemy's auto-fire rate. This piece does not work. The Enemy's firing stays the same rate all the time unless, wait for it, the Player dies. When the next spawn of the Player appears and auto-fire resumes toward it, the new Enemy firing delay value is used (and that value is apparently updating correctly, as multiple hits on the Enemy has indeed incrementally sped up the Enemy firing delay, err, rate upon Player re-spawn). So it is as if the "Every X Seconds" rule's expression is read and cached until some other fateful event occurs to jar/force a refresh of the expression used within it.

    And that Enemy "Every X Seconds" rule is not really tied into any other behaviors/timers/rules, so there is not other competing logic other than a master rule of if Player is not present, don't move or shoot. And again, the Enemy is auto-firing, so you think it would be re-assessing the "Every X Seconds" expression since firing is occuring.

    "Bug!", I dare say. Unless I am interpreting the behavior/rule/timer queing mechanism and if I am, it seems very inconsistent in how they are parsed.

    From what I have gathered from the Devs in various Forum posts:

    Sounds like all applicable steps are parsed in any order but likely from top to bottom mostly. Rules will allow/prevent behaviors under them from running. Timers will force behaviors running within them (but still under ruling of any parental rules/timers). Etc.
  • JGary321JGary321 Member Posts: 1,246
    Yea, I call bug also, b/c the way I have the rules setup there is no reason it shouldn't be changing. I've tried both Change & Constrain attribute. Hopefully this will get figured out at some point. Ah well, time for workarounds.
  • rebumprebump Member Posts: 1,058
    Yeah, I tried additional Change/Constrains, nested timers, different placement, re-adding the rules/behaviors, etc. No go.

    I think some of "Move Tos" issues may be related.
  • SlowboySlowboy Member, PRO Posts: 329
    Hi Chaps (I assume), I'd like to try what adent42 said about using a timed user input to generate a 'really random' number to then use as a seed for the 'not quite random' random function - but how on earth do I tell random to use a seed? I can't see anything on the wiki etc relating to seeds?
    Cheers
  • rebumprebump Member Posts: 1,058
    Not a seed in the traditional sense of a random number generator function but more of a random range to then generate a random number type scenario if I understood jhaas' idea. Be sure to go to jhaas' link up above. It is predicated on a timer waiting for user input...since each person will typically wait a different set of microseconds to complete input (i.e. some are slow, some quick, some distracted, whatever), you can ensure some randomness in a not-so-random random number generator (i.e. the seed).
  • ORBZORBZ Member Posts: 1,304
    a better seed of randomness instead of just the time time is x/y position of the mouse plus the time. that is a more guaranteed unique value.
  • rebumprebump Member Posts: 1,058
    True that ORBZ (assuming you are on a PC!). You could do something like: "Touch anywhere to continue..." and use the touch's info as well to setup the next piece of the app (i.e. the next scene or whatever).
  • SlowboySlowboy Member, PRO Posts: 329
    Ah, ok. Understood Rebump. It won't really help my particular situation then, but well worth keeping in mind for future.
    Cheers
  • rebumprebump Member Posts: 1,058
    When I said "assuming your are on a PC" above I meant "Mac" (i.e. since your iPhone won't have a mouse).
  • DhondonDhondon Member Posts: 717
    Has this function been fixed yet? Or is it just me being an noob?
  • amigoniamigoni Member Posts: 78
    Any solution on this? The range keeps getting smaller and my actors always go to the same location. As mentioned we can't use the iphone touch position as a seed cause it will just give the same thing since my actor is landing in the same spot.

    Thanks
  • I'm guessing from the lack of responses to the two prior posts, this is not fixed yet. Sad panda.

    I have three actors with random timers on them. Two of them tend to act correctly, but for some odd reason one of them always triggers at the "min" value over and over again.

    This is in now way meant to be a flamitory statement but; little bugs like this make me think twice about my GameSalad purchase. This is a great system with awesome developers and an even more impressive community. But this issue was brought to light nearly a year ago and still happens. I have a lot of love for you guys at G-Games, so please release more fixes...please?
  • BarkBarkCoBarkBarkCo Member Posts: 1,400
    How is this a bug? A random generator fed the same seed will always give you the same results. This is actually useful in some cases. Since the random function in this case is seeded with the game.time (I believe I read that somewhere) you will generally get the same results each run.

    You just need to feed the generator with some non-deterministic value in order to end the repetitive cycle.

    A common solution utilizing the above method is to create a button at the beginning of the game which asks the user to press to continue. When that button is pressed use some(any) behavior to call the random function and seed it with either the game.time (again, but different from the first time), or the X or Y values of the mouse, or even accelerometer data. Just something that will likely be different (even slightly) each time the game is played.
  • Right, but all of that is really a work around. A random timer function should work as described. Should someone HAVE to search through forums, then use a work around to get the random behavior as described in the behavior?

    I understand what you are saying for sure. But this is "Game development for the rest of us". Many of us need the functions to work simply as described rather than requiring a fairly detailed and potentially problematic work around.
  • synthesissynthesis Member Posts: 1,693
    Orbz suggested in another thread a while back to grab an accelerometer value (perhaps in conjunction with a random point in time) to generate a random seed value...since the device is rarely held in the same position twice. Then build your random sequences on that truly random seed.

    It seems like GS could build in a seed generation function fairly easily inside their GE...perhaps make it a checkbox boolean setting in the game attributes...to generate that new seed at game start. After 11 months...seems like they could have integrated this by now...but oh well.
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    I would love to see an example of this. Does mean that you use a change attribute to assign an accelerometer value to a real attribute and then use this as part of some equation in any rule that require randomness?

    Again I would love to see an example of how to implement this.
Sign In or Register to comment.