Page 1 of 1
I pass a number into a method but a table is returned
Posted: Thu Jul 11, 2019 4:46 pm
by shabbs15
Running the code, what's printed is 2 and then table followed by a series of characters. The second print statement is inside the function. I feel like this is a very simple question but I have a lot of code making it complex. I would appreciate any hel
Re: I pass a number into a method but a table is returned
Posted: Thu Jul 11, 2019 5:48 pm
by zorg
i see two places where you print to console:
- in sceneteleport, which as far as i can tell, is never called,
- in buttonclick, which, based on the defined buttons via createButton calls, either return 1, 2, or nil since there's one where you haven't set the 7th argument.
from your code, i can't tell what might be printing a table.
Re: I pass a number into a method but a table is returned
Posted: Fri Jul 12, 2019 4:08 pm
by shabbs15
zorg wrote: ↑Thu Jul 11, 2019 5:48 pm
i see two places where you print to console:
- in sceneteleport, which as far as i can tell, is never called,
- in buttonclick, which, based on the defined buttons via createButton calls, either return 1, 2, or nil since there's one where you haven't set the 7th argument.
from your code, i can't tell what might be printing a table.
The table is being printed in sceneteleport. Before I made the post, I did some tests "concatenating letters before the print" and this confirms that table is being printed from scenetelport.
Re: I pass a number into a method but a table is returned
Posted: Fri Jul 12, 2019 4:48 pm
by zorg
Then where in the code are you calling that function?
Re: I pass a number into a method but a table is returned
Posted: Sat Jul 13, 2019 12:35 am
by sphyrth
There's something funky with the code. I also can't tell where the function sceneTeleport(num) is being called. The problem seems to lie in these things:
Code: Select all
function createButton(x,y,width,height,func,scene,arg)
...
button.response = func
button.arg = arg
button.scene = scene
...
end
From this code, you seem to indicate that you want func to be a function.
But when we look at how you call createButton in bottomBar() for example:
Code: Select all
createButton(0,bottomCanvasY,MainCanvas:getWidth(),MainCanvas:getHeight(),SceneTeleport,0,1)
It looks like it's passing SceneTeleport as if it's a variable, or a function without arguments. (ex. SceneTeleport(1)).
With that, when buttonClick() happens:
Code: Select all
function buttonClick(x,y)
for i,v in pairs(buttons) do
if x > v.x and x < v.x+v.width and y > v.y and y < v.y+v.width then
if v.scene == 0 or scene == v.scene then
print(v.arg)
v:response(v.arg)
end
end
end
end
That v:response(v.arg) seems to be misplaced.
To sum up, I think there's something wrong with how you pass down arguments as functions.