Decimals, rounding, and the send to property

Hello,

I’m working on my first module, which has a larger map than usual. I’m setting it up so that each hex contains a randomly selected hex. I’ve done this by placing all the possible hexes I’ll use into a deck and giving each of them a send to property tied to a global hotkey. I hit the hotkey, a card moves, changes a variable I’ve named x by adding the length of a hex the x, then the next card moves to the new x,y position until a third variable that has been decrementing by 1 each time hits 0 and increments a y variable, resets the x variable, and spits out the next row.
I have that all sorted out, but I’ve ran into a problem. Each hex is 55.42562584220407 pixels of millimeters or however the things are measure wide, and the send two function doesn’t work with fractions I used the % operator to kill all the decimal places, but leaves me with a number ending in .0, which the send to property still thinks is a fraction. Is there any way to either:
A. round the number up or down automatically without leaving .0
B. kill the .0 at the end of my numbers
C. approach this a different way. I tried the send to location function instead of manually placing all the pieces, but my map is large enough that the thing shorts out and leaves a long column of hexes at the top of my screen and doesn’t fill in the lower half of the board

Math.round(x) will round x to the nearest integer (no “.0” at the end), if that’s acceptable.

Why not make the hexes have an integer value for width?

Or int() to get an integer.

Instead of screwing around with pixels and floating point, why not overlay your map with a hex grid and hex numbering? Then you can send your tiles to grid locations like a01, a02, …

3 Likes

Ok, I didn’t know about math.round. I stopped trying to use grid numbering because for some reason it dosent work right. It works fne down to the ninth row, but then the hexes start placing themselves off the map. I figured it out by making the hex sizes integer values.

1 Like