Jump to content

Some (simple) way to get the closest integer to a float?


12p

Recommended Posts

I don't know how to do this easier...

I have made this but isn't working as I want:

local intX,decX = math.modf(posX) 
            local intY,decY = math.modf(posY) 
            if decX >= -0.6 then 
                if decY >= -0.6 then 
                    block = createObject (model,intX,intY,posZ+0.5) 
                    table.insert(blocks,block) 
                    setElementID (block,tostring(table.getn(blocks)+1)) 
                    addObjectToMap(block) 
                elseif decY < -0.6 then 
                    block = createObject (model,intX,intY+1,posZ+0.5) 
                    table.insert(blocks,block) 
                    setElementID (block,tostring(table.getn(blocks)+1)) 
                    addObjectToMap(block) 
                end 
            elseif decX < -0.6 then 
                if decY >= -0.6 then 
                    block = createObject (model,intX+1,intY,posZ+0.5) 
                    table.insert(blocks,block) 
                    setElementID (block,tostring(table.getn(blocks)+1)) 
                    addObjectToMap(block) 
                elseif decY < -0.6 then 
                    block = createObject (model,intX+1,intY+1,posZ+0.5) 
                    table.insert(blocks,block) 
                    setElementID (block,tostring(table.getn(blocks)+1)) 
                    addObjectToMap(block) 
                end 
            end 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...