Why does this capx not work? random spawns?

  • Hello, thanks for any help.

    I have used this event before with a chest and it spawns diamonds around the chest when the chest explodes. However when the zombie dies, I want the zombie to spawn diamonds *5. However the event does not work.

    How can it work for one thing and not the other?

    Thank you

  • random(0) is 0, so I'm guessing your event spawns 5 gems all in the same position.

  • random(0) is 0, so I'm guessing your event spawns 5 gems all in the same position.

    Hi, Nah its not the 0. I have tried every variation of every number and sometimes they spawn at a random place or don't spawn at all. I cant find anything on youtube.

    Its a bit of a weird one. Cheers dop

  • Your Y is set to zombie.x instead of zombie.y

  • Your Y is set to zombie.x instead of zombie.y

    Yep! that done it lol. Jesus i am such a noob.

    Thanks Plinkie.

    Can I ask though please? what is this Zombie2red.X+floor

    (random

    (300)+100)

    It seems like the 300 scatters the diamonds more and the 100 pushes the diamonds more to the left.

    I just used this for the Y, it spawns the object a little above the ground. Zombie2red.y+floor (random(-10)+-10)

    I don't understand why there is two? (-10)+-10). surley one 0 would have been enough?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Your Y is set to zombie.x instead of zombie.y

    The first set of numbers seems to be spacing, and the second number position?

  • I don't quite follow as they're your events, right? :). Look at manual for random(x,y) it picks a random number between the ranges. When you add or subtract an amount from the zombie Y you are moving it up or down the screen so it will spawn above or below the zombie. If you do the same for zombie X then it moves the diamonds to the left or right of the zombie.

  • Thanks Plinkie, that makes sense. I get a bit confused when using a new event or parameter. The floor thing I learnt today so not sure if that was having any kind of impact.

    Quite handy though, I think I might try and play about with this and add a bullet behavior so they explode outwards and fall to floor.

    Cheers for the help!:-)

  • floor rounds it to a whole number because random can pick any number between ranges and you want a nice round co-ordinate instead of something like 8.74. No problem, gl :)

  • I just used this for the Y, it spawns the object a little above the ground. Zombie2red.y+floor (random(-10)+-10)

    I don't understand why there is two? (-10)+-10). surely one 0 would have been enough?

    if one zero would been enough then you would have a 1 instead of 10.

    as for (random(-10)+-10) the +- is a bit redundant u could've easy do (random(-10)+10) its the same thing as the +- negates itself and u remain with a 10 positive.

    If you would do random(0,10) then that would've been a different thing cause that would pick any number from 0 to 10.

    if you do (random(-10)+10) you are basically saying add a random(-value) to this sum with 10 or set X value to 10 + random(-value) is the same thing.

    now i dont know if this is explained or not in the manual, but my logic i think on it is

    random(0) picks any number from -infinity to +infinity

    random(-10) same thing but focuses on -infinity spectrum up to -10

    random(1) same as above but towards +infinity from 1

    (in ur picture u have random(0)+0) that means 0+random(any number + or - value)

    P.S(i never read the manual (outside the preface) >.> ... to much info, unclear what to focus on, in my case best example was using Construct and learn by doing, as its very intuitive and logical in the common sense of execution)

  • Man, there are so many mistakes in your comment... :)

    as for (random(-10)+-10) the +- is a bit redundant u could've easy do (random(-10)+10) its the same thing as the +- negates itself and u remain with a 10 positive.

    +- doesn't negate itself, it's the same as subtraction. (n+-10)=(n-10)

    So (random(-10)+-10) will return values from -20 to -10.

    random(0) picks any number from -infinity to +infinity

    No, random(0) is always 0.

    random(-10) same thing but focuses on -infinity spectrum up to -10

    No, when there is only one parameter, random returns values from 0 to that parameter, but not including it.

    So random(-10) will return values from -9.999999999.... to 0

    random(1) same as above but towards +infinity from 1

    Again, this will return values from 0 to 0.9999999999...

    (in ur picture u have random(0)+0) that means 0+random(any number + or - value)

    (random(0)+0) is obviously just 0

  • Man, there are so many mistakes in your comment... :)

    was it that obvious? ^_^ ... 2 years of blogging gone to the drain cause of this post i did ... im the new 4+7 =21 kid on the bloc :)))

  • Bloody maths man!! I actually went out and got myself a maths book!, I have been playing about with cos and stuff. Going to practice till I get it down :-).

    You have both been a great to me. I am 6 levels into my first (first of three failed games before). I am happy with the way the game is going and both of you, pinkie, maverick and some other dudes have been instrumental in providing me knowledge.

    A few games and I really want to create something really polished and epic. Until then you may keep seeing questions😜

    Thanks all

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