Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
need some help : trying to store my object's reference in table — Gideros Forum

need some help : trying to store my object's reference in table

jimlevjimlev Member
edited March 2013 in General questions
Another newbie question..

I probably do the things the bad way, but here is my problem:
I want to store in a table (name columnListOfGameTextBox ) all the instances of textfield that I dynamically create in my func

It seems to work well but when I print my table, the first entry is crap. Others work well... any idea ?
Does the way I want to do it is a foolish one ?
local columnListOfGameTextBox ={{0,0},{0,0},{0,0},{0,0}}
 
function createTextboxStage()    -- **********creation des txtfields du stage
 
		for i=1, 4 do   	
			for j=1, 2 do
				local txtbox = TextField.new(nil, "ABC")
				stage:addChild(txtbox)
 
				columnListOfGameTextBox[i][j]= txtbox   -- here I add the instance to my table
			end
		end
 
	printtbl(columnListOfGameTextBox)
 
end
 
function printtbl( t,tab,lookup )
    local lookup = lookup or { [t] = 1 }
    local tab = tab or ""
    for i,v in pairs( t ) do
        print( tab..tostring(i), v )
        if type(i) == "table" and not lookup[i] then
            lookup[i] = 1
            print( tab.."Table: i" )
            printtbl( i,tab.."\t",lookup )
        end
        if type(v) == "table" and not lookup[v] then
            lookup[v] = 1
            print( tab.."Table: v" )
            printtbl( v,tab.."\t",lookup )
        end
    end
end
 
createTextboxStage()
any idea ? 8-}
My meditation plan :
SinisterSoft: “ I don't create classes that much - classes are good for making things simpler but imho for frame rate they are also death by a thousand cuts.”
Totebo: “ Best quote ever.”
🤔

Comments

  • BJGBJG Member
    edited March 2013
    when I print my table, the first entry is crap. Others work well... any idea ?
    I get this output...

    1 table: 048A7C08
    Table: v
    1 0
    2 0

    2 table: 048A8580
    Table: v
    1 0
    2 0

    3 table: 048A7EC8
    Table: v
    1 0
    2 0

    4 table: 048A7F18
    Table: v
    1 0
    2 0

    Not sure what you mean about the first entry. What output did you want...? (I'm not sure what exactly you're trying to do...)

    Likes: jimlev

    +1 -1 (+1 / -0 )Share on Facebook
  • jimlevjimlev Member
    edited March 2013
    arf...
    I leave the 'problem' line commented in the sample code.

    try it now (example above shows the pb)

    here is the output I get :
    1	table: 042087C8
    Table: v
    	1	table: 04209468
    	Table: v
    		__userdata	userdata: 042094A8
    		__parent	table: 041FB540
    		Table: v
    			__userdata	userdata: 041FB580
    			__children	table: 04209550
    			Table: v
    				userdata: 00E22688	table: 042097C0
    				Table: v
    					__userdata	userdata: 04209848
    					__parent	table: 041FB540
    				userdata: 00E53908	table: 04209A18
    				Table: v
    					__userdata	userdata: 04209AA0
    					__parent	table: 041FB540
    				userdata: 00E4B838	table: 04209760
    				Table: v
    					__userdata	userdata: 042097A0
    					__parent	table: 041FB540
    				userdata: 00DE5D68	table: 04209680
    				Table: v
    					__userdata	userdata: 042096C0
    					__parent	table: 041FB540
    				userdata: 00E2FCA8	table: 042095C0
    				Table: v
    					__userdata	userdata: 04209600
    					__parent	table: 041FB540
    				userdata: 04572CE8	table: 04209468
    				userdata: 00E7F7D0	table: 04209858
    				Table: v
    					__userdata	userdata: 04209750
    					__parent	table: 041FB540
    				userdata: 00E07530	table: 041FB5B8
    				Table: v
    					__userdata	userdata: 04209628
    					__parent	table: 041FB540
    	2	table: 042095C0
    2	table: 04208D08
    Table: v
    	1	table: 041FB5B8
    	2	table: 04209680
    3	table: 04208690
    Table: v
    	1	table: 042097C0
    	2	table: 04209858
    4	table: 042093B0
    Table: v
    	1	table: 04209760
    	2	table: 04209A18
    My meditation plan :
    SinisterSoft: “ I don't create classes that much - classes are good for making things simpler but imho for frame rate they are also death by a thousand cuts.”
    Totebo: “ Best quote ever.”
    🤔
  • BJGBJG Member
    edited March 2013 Accepted Answer
    When presenting a problem it's best to explain what you're trying to achieve, how you're trying to achieve it, and the minimum amount of code needed to demonstrate the difficulty. Comments and meaningful variable names would also help. Otherwise it's too much like hard work. ;)

    (First the "printtb1" function is called with a single argument, then it calls itself with three arguments. I know Lua is fairly carefree about this kind of thing, but since it's apparently producing the wrong output the first time, I'm wondering if it's initially working with the wrong parameters. I don't understand what they should be though.)
  • jimlevjimlev Member
    edited March 2013
    When presenting a problem it's best to explain what you're trying to achieve, how you're trying to achieve it, and the minimum amount of code needed to demonstrate the difficulty.
    I really don't know what ur talking about :-/ Everything looks extremly clear... for me :D
    I'm going to clean the code a "little bit" or, better, make a simplified version and try to explain the goal behind that mess

    thx BJG
    My meditation plan :
    SinisterSoft: “ I don't create classes that much - classes are good for making things simpler but imho for frame rate they are also death by a thousand cuts.”
    Totebo: “ Best quote ever.”
    🤔
Sign In or Register to comment.