[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.
Post Reply
User avatar
icekiller8002
Prole
Posts: 49
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

Post 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
Attachments
Pointless.love
(12.98 KiB) Downloaded 149 times
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
User avatar
icekiller8002
Prole
Posts: 49
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

Post 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:

Code: Select all

function love.draw()
  love.graphics.print("obey")
end
User avatar
pgimeno
Party member
Posts: 3548
Joined: Sun Oct 18, 2015 2:58 pm

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

Post by pgimeno »

tempd is a string. In Lua, "3" does not equal 3, therefore none of the comparisons in autoMove() matches.
User avatar
icekiller8002
Prole
Posts: 49
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

Post 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:

Code: Select all

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

Who is online

Users browsing this forum: Google [Bot] and 62 guests