Page 1 of 1

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

Posted: Fri May 31, 2019 4:39 pm
by icekiller8002

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

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

Posted: Fri May 31, 2019 5:17 pm
by icekiller8002
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 :huh:

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

Posted: Fri May 31, 2019 5:25 pm
by pgimeno
tempd is a string. In Lua, "3" does not equal 3, therefore none of the comparisons in autoMove() matches.

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

Posted: Fri May 31, 2019 5:28 pm
by icekiller8002
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! :awesome: