Activate event with multiples of 10?

Don't know how to make something and can't find a tutorial? Ask for one here.

Activate event with multiples of 10?

Postby DanielWero » Fri Feb 14, 2014 8:11 pm

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?
DanielWero
 
Posts: 4
Joined: Thu Feb 13, 2014 9:37 pm
Location: México
Score: 0 Give a positive score

Re: Activate event with multiples of 10?

Postby CrackedP0t » Fri Feb 14, 2014 10:54 pm

You'll need to be a bit clearer.
/人 ◕‿‿◕ 人\
Fang Pictures, my game development company:
http://fangpictures.comuf.com
User avatar
CrackedP0t
 
Posts: 157
Joined: Mon Dec 30, 2013 5:49 pm
Location: Crested Butte, CO (The US of A)
Score: 8 Give a positive score

Re: Activate event with multiples of 10?

Postby DarkParadox » Sat Feb 15, 2014 12:03 am

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
}
User avatar
DarkParadox
 
Posts: 457
Joined: Mon Jan 08, 2007 11:32 pm
Location: USA, Florida.
Score: 84 Give a positive score

Re: Activate event with multiples of 10?

Postby DanielWero » Sun Mar 02, 2014 1:20 am

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?
DanielWero
 
Posts: 4
Joined: Thu Feb 13, 2014 9:37 pm
Location: México
Score: 0 Give a positive score

Re: Activate event with multiples of 10?

Postby DarkParadox » Sun Mar 02, 2014 3:46 am

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.
User avatar
DarkParadox
 
Posts: 457
Joined: Mon Jan 08, 2007 11:32 pm
Location: USA, Florida.
Score: 84 Give a positive score

Re: Activate event with multiples of 10?

Postby DanielWero » Thu Mar 06, 2014 5:22 pm

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 :(
DanielWero
 
Posts: 4
Joined: Thu Feb 13, 2014 9:37 pm
Location: México
Score: 0 Give a positive score

Re: Activate event with multiples of 10?

Postby lcl » Thu Mar 06, 2014 5:39 pm

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.
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Activate event with multiples of 10?

Postby DanielWero » Wed Mar 26, 2014 5:48 pm

Thanks you very much my friend! :D
DanielWero
 
Posts: 4
Joined: Thu Feb 13, 2014 9:37 pm
Location: México
Score: 0 Give a positive score


Return to Tutorial Requests

Who is online

Users browsing this forum: No registered users and 1 guest