Random Problem

ricardorauberricardorauber Member Posts: 26
edited November -1 in Working with GS (Mac)
Hello there! I have a problem with random function when it's called from a spawned actor.

I have 2 actors, let me explain what they do:

Actor 1:
Rule - mouse button is down
Spawn Actor 2

Actor 2:
Display Text - random(1,100)
Timer - After 2 seconds
Destroy

Ok, what's the problem? When I click on the Actor 1, the Actor 2 appear with some value and after 2 seconds it left. The problem is that every time one Actor 2 is spawned, it always came with the same value!

Example:
I click on Actor 1;
Actor 2 appear with value 32;
After 2 seconds Actor 2 disappear;
I click again on Actor 1;
Actor 2 appear with the same 32 value!

Why the value is not random??

Comments

  • ricardorauberricardorauber Member Posts: 26
    xSlamGx

    Thanks for the reply but it doesn't work, I'm still getting the same value!

    When I click 2 times on Actor 1, the second one appear with other value but it seems to be always the same numbers.
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    Hi Ricardo, definitely got something to do with the fact of destroying the actor every time. If you delete the destroy Actor 2 temporarily, you'll see it'll work OK.

    One way of working it, would be to make your Actor 2 with 0 Alpha. Also, to avoid double clicks, make a game attribute called Active, for instance. In Actor 1's Rules, not only put when mouse button is down but also when game.Active is false, then change game.Active to True, and add Change Attribute, making Actor 2's Alpha to 1.

    In Actor2, your random stuff, then a 2 sec. timer to change its Alpha to 0, and another Change Attribute, seting Active to false.

    Hope that makes sense the way i've written it and hope it helps.

    :-)

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • scitunesscitunes Member, Sous Chef Posts: 4,047
    Random isn't really random in GS:

    http://gamesalad.com/forums/topic.php?id=862
  • IntelligentDesignerIntelligentDesigner Member Posts: 517
    For Random to work, you have to use a different seed every time. GameSalad does not have a way to do this, I think, but it's hard to tell with no documentation.
  • ChunkypixelsChunkypixels Member Posts: 1,114
    So there appears to be documented evidence of Random not working correctly going back at least 9 months, and it appears in topics on a regular basis.

    So why hasnt it been fixed yet? Why are people expected to have to figure out work arounds for a function that has been in the engine/editor for so long, but just isnt working correctly? Is it even in a GameSalad bugfix list?

    This is a pretty major function for game development, and pretty shabby for it to not work correctly for so long.... its the kind of basic engine maintenance that should be top priority when it comes to the updates.

    Please Gendai, concentrate on fixing broken stuff, and improve the editor, rather than worrying about new features all the time.... and you'd make me a happy developer.
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    I remember people complaining about random when I was dabbling with RealBasic, and then when I moved on to RunRev. I wish I could remember all the technical details that guys over on their Forum were putting forward as the reasons why random in a lot of programs isn't true random.

    But as far as I've found, although random doesn't work in Display text, by changing an attribute Rand on mouse up for instance, to random(min,max), then the Text in Display Text to be self.Rand, (I know you guys know that) you get pretty much random numbers, although I'm told not true random, but the randomness seems good enough to me!

    I'm guessing the broken random your referring to is random in Display Text?

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • ricardorauberricardorauber Member Posts: 26
    Thanks all for the replys! I have reported this bug and now I'm trying to do the random in other way.

    Following that topic that scitunes said, I'm using the milliseconds to get some random numbers but even that doesn't work perfect.
  • ricardorauberricardorauber Member Posts: 26
    Hey guys, I found the reason of the problem!

    First of all, there is no problem with the random function. What happened is that Display Text on the spawned actor changes only on the first time! I put other actor displaying the same game attribute and it worked perfect.

    With these things, I had the change the logic and now works!

    Once again, thanks for all replys!
  • ricardorauberricardorauber Member Posts: 26
    Problem solved.
  • PlaySysPlaySys Member Posts: 17
    Isn't there a way to obtain the date and clock value from the OS? Maybe that can be used to generate a good seed.
    I'm becoming crazy with this random value, I need one when the game starts and I can't use game.time because, of course, is always the same.
Sign In or Register to comment.