Random Function No Way Random
TheT
Member Posts: 80
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 !
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
http://img21.imageshack.us/i/screenu.tif/
http://gamesalad.com/forums/topic.php?id=862#post-4795
Any real statements, maybe from the side of the developers ?
Thanks !
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
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
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!
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
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.
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.
I think some of "Move Tos" issues may be related.
Cheers
Cheers
Thanks
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?
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.
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.
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.
Again I would love to see an example of how to implement this.