Posted 22 August 2014 - 04:35 PM
Hey Forum,
I am still trying to get my button api running.
I am already able to draw the buttons and let them trigger actions and all the basic stuff.
But inside my button.createButton(…) method I am adding the button in a separate table where all the buttons are stored.
Seems like no big deal but now I´ve come across a problem that I really do not understand:
So far I only added some values inside my buttonlist like this :
Now I thought it would be easier to simply add the whole button table inside my list like that:
Because self is a table I dont need that {} brackets (well at least I think so?).
Anyway: When I click my button and the function detectClick() tries to find out if a button was clicked, he fails to get the values out of my self table inside of my list.
So thats the code:
At the point where I try to get the length of button_list[1] (the name is stored at the first index) the console tells me"cant get length of nil" .
When I add the values normally like I said at the beginning everything works fine, only if I insert the whole self table it fails ?
It would be a lot easier for me just to add the self table but currently I am clueless why this doesn´t work ?!
Please help me :)/>
Kouksi44
I am still trying to get my button api running.
I am already able to draw the buttons and let them trigger actions and all the basic stuff.
But inside my button.createButton(…) method I am adding the button in a separate table where all the buttons are stored.
Seems like no big deal but now I´ve come across a problem that I really do not understand:
So far I only added some values inside my buttonlist like this :
table.insert(button_list,{self.name,self.intx,self.inty,self.width,self.action})
Now I thought it would be easier to simply add the whole button table inside my list like that:
table.insert(button_list,self)
Because self is a table I dont need that {} brackets (well at least I think so?).
Anyway: When I click my button and the function detectClick() tries to find out if a button was clicked, he fails to get the values out of my self table inside of my list.
So thats the code:
function detectClick(posX,posY)
for i=1,#button_list do
if
posX<=button_list[i][2]+#button_list[i][1] and
posX>= button_list[i][2] and
posY <= button_list[i][3]+button_list[i][4] and
posY >=button_list[i][3]
then
return button_list[i][1]
end
end
end
At the point where I try to get the length of button_list[1] (the name is stored at the first index) the console tells me"cant get length of nil" .
When I add the values normally like I said at the beginning everything works fine, only if I insert the whole self table it fails ?
It would be a lot easier for me just to add the self table but currently I am clueless why this doesn´t work ?!
Please help me :)/>
Kouksi44