Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
1 registered members (Dico), 16,767 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Rounding numbers #416006
01/27/13 00:58
01/27/13 00:58
Joined: Dec 2009
Posts: 361
R
rtsgamer706 Offline OP
Senior Member
rtsgamer706  Offline OP
Senior Member
R

Joined: Dec 2009
Posts: 361
Hi, I would like to know how to round numbers.
I have an entity and I need it's position to be rounded to the nearest number divisible by ten once it's finished moving.
I have an if statement that works with a variable counter so that I have a block which will activate once the entity has stopped moving.
In this block I added a line saying:

if (my.x % 10 != 0)

but I have no idea what to do if the if statement is met.
Thanks for your help and if anything in the post is unclear please let me know so that I can clarify.
Rtsgamer706

Re: Rounding numbers [Re: rtsgamer706] #416007
01/27/13 01:21
01/27/13 01:21
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
I wouldn't use an if statement here. Just round the number:
Code:
roundedNumber = integer(rawNumber * .1 + .5) * 10;



Always learn from history, to be sure you make the same mistakes again...
Re: Rounding numbers [Re: rtsgamer706] #416008
01/27/13 01:26
01/27/13 01:26
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
If you are using a grid like system and you want to know the current grid id of your entity, something as follows works quite nicely:

id_x = floor(my.x/10);
id_y = floor(my.y/10);

You can shift the position naturally if the ids don't match your system (i.e. an entity receives the next higher id too early when moving in one direction):

id_x = floor((my.x-5)/10);
id_y = ...


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: Rounding numbers [Re: Uhrwerk] #416009
01/27/13 01:34
01/27/13 01:34
Joined: Dec 2009
Posts: 361
R
rtsgamer706 Offline OP
Senior Member
rtsgamer706  Offline OP
Senior Member
R

Joined: Dec 2009
Posts: 361
that worked, thanks for the help


Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1