I pass a number into a method but a table is returned
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
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
- (6.62 KiB) Downloaded 83 times
- zorg
- Party member
- Posts: 3465
- 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.
- 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.
Re: I pass a number into a method but a table is returned
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 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.
- zorg
- Party member
- Posts: 3465
- 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.
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:
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:
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:
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.
Code: Select all
function createButton(x,y,width,height,func,scene,arg)
...
button.response = func
button.arg = arg
button.scene = scene
...
end
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)
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
To sum up, I think there's something wrong with how you pass down arguments as functions.
Who is online
Users browsing this forum: Bing [Bot], Semrush [Bot] and 3 guests