Page 1 of 1

Pass table index instead of table value

Posted: Thu Mar 03, 2016 10:20 pm
by feelixe
Hi, the answer to this might be really simple and maybe im just retarded but..
Im curently making a custom Messagebox , with a text input. The goal is to halv something like

Code: Select all

Table = { valueone = "" }
So my options are to either:

Code: Select all

table.valueone = inputbox:new()
But that would have to "pause" the whole game, right? Until the function returns something

The other thing i thought of was

Code: Select all

inputbox(table.valueone)
And then the function would set the input to the input from the textbox. However when i pass table.valueone to the function it sends its string value instead of like a refrense to the table.

Hope you understand what i mean. Any help is appriciated

Re: Pass table index instead of table value

Posted: Thu Mar 03, 2016 10:36 pm
by s-ol
well you can do

Code: Select all

inputbox(table, "valueone")

function inputbox(tbl, key)
  tbl[key] = .....
end
but you still need to "wait" for inputbox to return. And I don't see what the problem is with table.valueone = inputbox() in the first place.

Re: Pass table index instead of table value

Posted: Thu Mar 03, 2016 10:39 pm
by feelixe
S0lll0s wrote:well you can do

Code: Select all

inputbox(table, "valueone")

function inputbox(tbl, key)
  tbl[key] = .....
end
but you still need to "wait" for inputbox to return. And I don't see what the problem is with table.valueone = inputbox() in the first place.
but if i do table.valueone = inputbox(), then wouldn't the game freeze until i press OK in my custom messagebox and inputbox() returns a value so it can continue in the code?

and if i do:

Code: Select all

inputbox(table, "valueone")

function inputbox(tbl, key)
  tbl[key] = .....
end
i can store (tbl, key) in a table of all the inputboxes and the apply it when OK is pressed, however this doesn't feel as neat.

Re: Pass table index instead of table value

Posted: Thu Mar 03, 2016 11:27 pm
by s-ol
You need to decouple the call and the game loop anyway then, there is no other way i can think off except having a callback-style approach.