How do I - Math - How does int() work?

Just started using Construct 2? Post your questions here

Post » Wed Jul 22, 2015 1:21 am

I'm using an event - in this event, I have [System - pick sprite where sprite.X DOES NOT EQUAL int(1-5)


Would int(1-5), is this actually 1 minus 5? or is this pick 1 through 5?

What I WANTED to accomplish was, I wanted the system to pick every sprite that DID NOT HAVE these specific values.

Is this possible?

For example, if the sprite.HP is NOT 1,2,3,4,5, I would like the system to select those sprites.



I read the manual on the math expressions but I think I would understand it better if I had someone really dumb it down for me. :oops:

Thanks for the help.
B
6
S
2
Posts: 60
Reputation: 1,242

Post » Wed Jul 22, 2015 1:39 am

The int() expression turns a float (number with decimals) to a whole number, rounded down to the next lowest whole number. So, int(1-5) is the same as int(-4) which equals: -5. Probably not what you were hoping for... The c2 event system is incredibly powerful and will filter/pick all instances that satisfy a condition or conditions that you define.

So, for your example, are the sprite.HP values all integers (ie whole numbers)? If so, you could use this OR condition to pick all of the relevant sprites:

Sprite.HP > 5
or
Sprite.HP < 1
A big fan of JavaScript.
B
76
S
20
G
73
Posts: 2,244
Reputation: 45,962

Post » Wed Jul 22, 2015 3:43 am

Thank you for your help Colludium, that really clears some things up for me.

But now I have another question. - Where do I input the OR condition?

do I type it in as a string? Is it somewhere under the system conditions? I tried typing it in in the "Value" box,

I wondered if it was an event such as "else" ? - Ah wait, did you mean an "OR block"?

Ahh I see I understand clearly now.

For everyone else looking for it - https://www.scirra.com/manual/75/how-events-work

Thank you very much Colludium, wish I could +1 you or something.
B
6
S
2
Posts: 60
Reputation: 1,242

Post » Fri Jul 24, 2015 3:03 pm

Select your event (not on top, on left side) right click and choose Make 'Or' block
B
21
S
8
G
6
Posts: 177
Reputation: 8,134

Post » Sat Jul 25, 2015 10:07 am

mrcgkh wrote:Select your event (not on top, on left side) right click and choose Make 'Or' block


Yeah, this definitely is something I wish I knew when I started using C2.

Clicking the far left has a difference than clicking slightly to the right of the far left.

Learning that has definitely improved my workflow.
B
6
S
2
Posts: 60
Reputation: 1,242


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 0 guests