Page 1 of 1

Activate event with multiples of 10?

PostPosted: Fri Feb 14, 2014 8:11 pm
by DanielWero
Hi, this is my first post in this forum, but I hope my question is resolved. ¿How do I need to make to create a object, every time than the score reached is a multiple of 10?

Re: Activate event with multiples of 10?

PostPosted: Fri Feb 14, 2014 10:54 pm
by CrackedP0t
You'll need to be a bit clearer.

Re: Activate event with multiples of 10?

PostPosted: Sat Feb 15, 2014 12:03 am
by DarkParadox
You can use the modulus operator, "%", with an if statement.
"%" is like division with "/", but returns the remainder of the division. E.g. "3 % 10" would return "1" since "3" goes into "10" three times with one left over. You can check for multiples by using this and seeing if there's any remainder, and if there isn't, it was cleanly divisible.
Code: Select all
if(score % 10 == 0) // Goes into 10 with no remainder
{
    // Code to do on multiples here
}

Re: Activate event with multiples of 10?

PostPosted: Sun Mar 02, 2014 1:20 am
by DanielWero
DarkParadox wrote:You can use the modulus operator, "%", with an if statement.
"%" is like division with "/", but returns the remainder of the division. E.g. "3 % 10" would return "1" since "3" goes into "10" three times with one left over. You can check for multiples by using this and seeing if there's any remainder, and if there isn't, it was cleanly divisible.
Code: Select all
if(score % 10 == 0) // Goes into 10 with no remainder
{
    // Code to do on multiples here
}


Sorry! But I'm very silly, Because I wrote it as I understood but the "Game Editor" puts me this:
Sin título.png
My screenshot
. What am I doing wrong?

Re: Activate event with multiples of 10?

PostPosted: Sun Mar 02, 2014 3:46 am
by DarkParadox
I take it you're just starting to learn C (the programming language Game-Editor uses) then?
What you did is a common early-learning syntax error, you put a semicolon after the if() statement.
Code: Select all
if(condition);
{
  // stuff
}

These sort of conditional statements, like IF and WHILE, can't have a semicolon after them, or they don't do anything.
Code: Select all
if(condition)
{
  // stuff
}


Your condition is also wrong:
What I wrote earlier is the correct code ("score % 10 == 0"). You see, you can think of the "%" modulus operator as any other kind of operator, like "+" or "-". The code in "score % 10" will, instead of doing something like "score + 10", return the remainder of a division from "score / 10". For example, if "score" was "15", and you did "score % 10", it would give you "5" because 10 only goes into 15 once, with "5" left over.
The second half of it, "score % 10 == 0" checks if the remainder is "0", meaning that the number is cleanly divisible by 10.
Code: Select all
if(score % 10 == 0)
{
  // Code to do if score is a multiple of ten
}


P.S.
Code after a "//" on a line is a comment in the C programming language.

Re: Activate event with multiples of 10?

PostPosted: Thu Mar 06, 2014 5:22 pm
by DanielWero
Oh, thanks for the explanations, for curiosity, ¿do you have a Youtube channel of tutorials or something? you really explain very well :D . However, i still have problems with the game, I did all the things you said me, but the GE says me this:
Sin título.png
. What i doing wrong?
PD: Forgive me for not understanding, i feel very fool :(

Re: Activate event with multiples of 10?

PostPosted: Thu Mar 06, 2014 5:39 pm
by lcl
You have two errors there.

First off, you have to have two ='s in if conditions.
Second, you can't use textNumber there, as it is a floating point number, and the '%' operator requires you to only use integer values.
To fix that, simply cast it to an integer. Like this:
Code: Select all
if ((int)score.textNumber % 10 == 0)
{
    //here comes the create actor code
}

So the '(int)' tells the program that score.textNumber should be treated as an integer value here, and so it leaves out the decimals.

Re: Activate event with multiples of 10?

PostPosted: Wed Mar 26, 2014 5:48 pm
by DanielWero
Thanks you very much my friend! :D