Gamestudio Links
Zorro Links
Newest Posts
Zorro tutorial ideas?
by mistery. 10/21/26 05:28
Avoid "log\ - delete old files" message
by Martin_HH. 10/20/26 07:23
Missing PnL files in zOpen child processes
by DonQuijote. 10/19/26 11:11
ZorroGPT
by TipmyPip. 10/15/26 08:28
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
1 registered members (TipmyPip), 10,458 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
JimSimons, julienp, julienper, KelleyAbbey, Yopachi
19246 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