Pass table index instead of table value

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
feelixe
Prole
Posts: 36
Joined: Tue Aug 20, 2013 10:29 am

Pass table index instead of table value

Post 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
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: Pass table index instead of table value

Post 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.

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
feelixe
Prole
Posts: 36
Joined: Tue Aug 20, 2013 10:29 am

Re: Pass table index instead of table value

Post 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.
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: Pass table index instead of table value

Post 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.

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 44 guests