Is this a wrong code?

0 favourites
  • 4 posts
From the Asset Store
5 levels with simple coding Source-code (.c3p) + HTML5 Exported
  • Hi everyone

    I'm using a global variable to create a random objects, But sometimes this event won't trigger, i don't know what's wrong with it:

    Global variable = NumbersVar

    On start of layout ------ System set NumbersVar to floor(random(1,52))

    NumbersVar = 1

    Trigger once -------- create object A

    NumbersVar = 2

    Trigger once -------- create object B

    Etc...

    Objects family on destroyed ----- System set NumbersVar to floor(random(1,52))

    ------------------------

    Thanks for any help guys

  • It wouldn't trigger if the same random number is used twice in a row. A possible solution that would require minimal modification to your events would be to set the number to 0 and the set it to a random number from there.

    Global variable = NumbersVar
    
    On start of layout ------ System set NumbersVar to 0
    
    NumbersVar = 0
    Trigger once -------- System set NumbersVar to floor(random(1,52))
    
    NumbersVar = 1
    Trigger once -------- create object A
    
    NumbersVar = 2
    Trigger once -------- create object B
    
    Etc...
    
    Objects family on destroyed ----- System set NumbersVar to 0
    [/code:2hlxs7ca]
  • I would expect on the start of your layout if Random() doesn't produce a 1 or a 2 then those triggers would not happen.

    Are Family Objects being destroyed a lot? i.e. is that OnDestroyed event being triggered a lot?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • R0J0hound thanks for the answer, now it's working fine.

    jobel yes, the event will trigger very lot, it's an endless numbers game.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)