Can't seem to get random timer to work correctly.

Granted I've been playing with this program for 12 hours. I feel I have a pretty good handle on it so far.

Basically I have an actor that is spawning another actor randomly. I set the timer and I set it to random (2, 8) seconds or whatever. The actor spawns just fine, but its at a very steady pace not a random pace at all. I cannot figure out what could be the problem. Pulling my hair out so going to sleep. Really nice program this is though.

Anyone have problems with random in windows sometimes?

Comments

  • SocksSocks London, UK.Member Posts: 12,822
    edited December 2014

    @lilpoboy1978 said:
    I set the timer and I set it to random (2, 8) seconds or whatever.

    'Whatever' !? :o :)

    Details in a programming language are as important as numbers in maths, ideally you would say what kind of timer you are using (For ? Every ? After ? . . . etc), the more people have to guess information (information you already know) the slower it tends to be getting a solution to an issue.

    I'm going to guess you are usng 'Every' as this issue often comes up with an 'Every' timer.

    'Every' seems (to me at least) to lose its meaning when the value it refers to only happens once, which would be the case if each step were random, that is to say if 'every' means 'all of . . . ' then it seems odd to say 'all XXXs . . . ' to only then reference one XXX.

    Let's imagine the thing we are referencing is a random length of time (which is exactly what you are trying to do, but let's scale it up a bit) . . . . that random progression of values might read: I want X to happen every day of the week, but after just one day it then needs to be every hour, then after just one hour it needs to be every week, then after just one week it needs to be every minute, then after just one minute . . . etc . . as you can see in a random progression 'every' looses its meaning.

    Hope that makes some sense !?

    Or to put it another way:

    A: "I want X to happen every Saturday"

    B: "Ok, no problem, so once a week then ?"

    A: "No, I want it to be random, so after the first Saturday it should be some other random day of the week"

    B: "So not every Saturday then ?"

    :wink:

    So, 'Every' in a timer works as I'd expect it to work, it selects a random value and then does whatever it is asked to do at 'every' interval defined by the randomly selected value, so if it randomly selects 3, then it will do its thing 'every' 3 seconds.

    That is to say that the timer you are using is working correctly. Unless you're not using 'Every', in which case ignore all this :D

    'After' seems like a better candidate for a random progression of values.

    Game attribute ('X')

    The spawner: After X seconds - change X to random (2,8) - Spawn the other actor - Spawn The spawner - Destroy.

  • AssortDisAssortDis Member, PRO Posts: 22

    Nice explanation @Socks‌, I didn't know about this Every timer problem. I was almost making the same mistake there.

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598

    Hi @lilpoboy1978 and welcome to the Forums and GSC. :smile:

    Neat explanation about Timers from @Socks there, I'll say too.

    Try the following, see if it helps: make an integer attribute, call it Rand, another attribute, boolean, call it Trigger

    Rule: When Trigger is false
    Change Attribute Rand to random(2,5)
    Timer: After Rand Seconds
    Spawn
    Change Attribute Trigger to true
    
    Rule: When Trigger is true
    Change Attribute Trigger to false
    

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

  • lilpoboy1978lilpoboy1978 Member Posts: 1

    @gyroscope said:
    Hi lilpoboy1978 and welcome to the Forums and GSC. :smile:

    Neat explanation about Timers from Socks there, I'll say too.

    Try the following, see if it helps: make an integer attribute, call it Rand, another attribute, boolean, call it Trigger

    Rule: When Trigger is false
    Change Attribute Rand to random(2,5)
    Timer: After Rand Seconds
    Spawn
    Change Attribute Trigger to true
    
    Rule: When Trigger is true
    Change Attribute Trigger to false
    

    I will do this. Makes alot of sense. also thanks to Socks.

    Apologies for saying "whatever" in my post. I was frustrated.

Sign In or Register to comment.