How do I round up numbers from 53-> 64 & 25 -> 32, etc...

Get help using Construct 2

Post » Thu Jan 29, 2015 9:55 am

Not sure if the title is correct, but what I am asking for is how do i get a number like 57 to become rounded to 64. 34 to 32, etc...
I am currently working on a grid system where i want an object to jump between grids to not go smoothly over corresponding to my mouse x & y coordinates. I want the numbers of my coordinates to pick the closest 32x.
B
9
S
2
Posts: 41
Reputation: 1,756

Post » Thu Jan 29, 2015 10:09 am

Something like

round(int(YOURVALUE)/32)*32
If your vision so exceeds your ability, then look to something closer.
Moderator
B
137
S
31
G
87
Posts: 5,540
Reputation: 60,424

Post » Thu Jan 29, 2015 10:13 am

@zenox98 - is that int() really necessary?
B
19
S
6
G
7
Posts: 1,101
Reputation: 6,146

Post » Thu Jan 29, 2015 10:14 am

zenox98 wrote:Something like

round(int(YOURVALUE)/32)*32


Thanks a lot! It worked.
B
9
S
2
Posts: 41
Reputation: 1,756

Post » Thu Jan 29, 2015 10:16 am

I was using text boxes as a test, so for this, yes. If it was a variable, probably not.
You do not have the required permissions to view the files attached to this post.
Last edited by zenox98 on Thu Jan 29, 2015 10:20 am, edited 1 time in total.
If your vision so exceeds your ability, then look to something closer.
Moderator
B
137
S
31
G
87
Posts: 5,540
Reputation: 60,424

Post » Thu Jan 29, 2015 10:19 am

Ah, I see. So @HPA97 - if your values are already numbers you can omit that int - just have round(yourvalue/gridspacing)*gridspacing. Perhaps saves a picosecond of processing time somewhere :)
B
19
S
6
G
7
Posts: 1,101
Reputation: 6,146

Post » Thu Jan 29, 2015 10:21 am

@Somebody
I just amended post for clarity, but you beat me to it :)
If your vision so exceeds your ability, then look to something closer.
Moderator
B
137
S
31
G
87
Posts: 5,540
Reputation: 60,424

Post » Thu Jan 29, 2015 10:28 am

Heh, heh. Just to needlessly inflate this topic even more - sometimes the sudden jump of a rounded value when it goes from, say 0.49 to 0.51 can be jarring in that case you can replace round with floor() or ceil() to get the lowest and highest values respectively. I prefer that on a grid, but it's a matter of taste.
B
19
S
6
G
7
Posts: 1,101
Reputation: 6,146

Post » Thu Jan 29, 2015 10:28 am

Somebody wrote:Ah, I see. So @HPA97 - if your values are already numbers you can omit that int - just have round(yourvalue/gridspacing)*gridspacing. Perhaps saves a picosecond of processing time somewhere :)


Thanks, you guys are realy helpfull! Much appreciated!
B
9
S
2
Posts: 41
Reputation: 1,756



Return to How do I....?

Who is online

Users browsing this forum: max2612 and 7 guests