## [SOLVED] I have no clue why, but my function only accepts integer numbers, not variables

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
icekiller8002
Prole
Posts: 38
Joined: Mon Jun 06, 2016 9:28 pm
Location: United States

### [SOLVED] I have no clue why, but my function only accepts integer numbers, not variables

Code: Select all

entdata = {1,0,6,3}
-- a is the room number, b and c are the x and y coordinates for the next room, d is the direction (3 is right)
local a,b,c,d = entdata[transport][1],entdata[transport][2],entdata[transport][3],entdata[transport][4]
tempd = d
loadMap(a,b,c,d) -- i use local variables because the entdata table is cleared upon loading the next room

-- later in the code --
autoMove(3) -- works
-- v.s. --
autoMove(tempd) -- doesn't work

-- autoMove function --
function autoMove(dire)
moving = true
pl.d = dire
if pl.d == 0 then
sprY = 51
elseif pl.d == 1 then
sprY = 102
elseif pl.d == 2 then
sprY = 0
elseif pl.d == 3 then
sprY = 153
end
end

basically, autoMove() works when i use an actual integer value, but it doesn't work when i use tempd, even though tempd is equal to 3

i went ahead and attached a .love file if what i provided isn't enough information for you
Attachments
Pointless.love
Last edited by icekiller8002 on Fri May 31, 2019 5:31 pm, edited 1 time in total.

Code: Select all

function love.draw()
love.graphics.print("obey")
end


icekiller8002
Prole
Posts: 38
Joined: Mon Jun 06, 2016 9:28 pm
Location: United States

### Re: I have no clue why, but my function only accepts integer numbers, not variables

update: i found out that when I use autoMove(tempd), it sets moving to true and it plays the movement animation, but it doesn't move the character. i have no clue why, because pl.d is equal to 3, but it's just not moving the player

Code: Select all

function love.draw()
love.graphics.print("obey")
end


pgimeno
Party member
Posts: 2305
Joined: Sun Oct 18, 2015 2:58 pm

### Re: I have no clue why, but my function only accepts integer numbers, not variables

tempd is a string. In Lua, "3" does not equal 3, therefore none of the comparisons in autoMove() matches.

icekiller8002
Prole
Posts: 38
Joined: Mon Jun 06, 2016 9:28 pm
Location: United States

### Re: I have no clue why, but my function only accepts integer numbers, not variables

pgimeno wrote:
Fri May 31, 2019 5:25 pm
tempd is a string. In Lua, "3" does not equal 3, therefore none of the comparisons in autoMove() matches.
so i just have to simply use tempd = tonumber(d)?

EDIT: i tried it, and it worked. thanks!

Code: Select all

function love.draw()
love.graphics.print("obey")
end


### Who is online

Users browsing this forum: Bing [Bot] and 11 guests