## I pass a number into a method but a table is returned

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
shabbs15
Prole
Posts: 6
Joined: Sat Jun 29, 2019 8:43 am

### I pass a number into a method but a table is returned

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
Attachments
main.lua

zorg
Party member
Posts: 2774
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

### Re: I pass a number into a method but a table is returned

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.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.

shabbs15
Prole
Posts: 6
Joined: Sat Jun 29, 2019 8:43 am

### Re: I pass a number into a method but a table is returned

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.

zorg
Party member
Posts: 2774
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

### Re: I pass a number into a method but a table is returned

Then where in the code are you calling that function?
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.

sphyrth
Party member
Posts: 108
Joined: Mon Jul 07, 2014 11:04 am
Contact:

### Re: I pass a number into a method but a table is returned

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.

### Who is online

Users browsing this forum: No registered users and 15 guests