I'm making a copy of a table, and I want the new table to only use a specific subset of the original. What I'm not sure is how that would work in LUA language?
1 2 3 4 | local newTable={} for i=1,50 and otherTable[i].Job="Shopkeep" do newTable[i]= { name=otherTable[i].Name, Job="Shopkeep" } end |
i think it should be as below..
1 2 3 4 5 6 | local newTable={} for i=1,50,1 do if otherTable[i].Job == "Shopkeep" do newTable[i]= { name=otherTable[i].Name, Job="Shopkeep" } end end |
Trying to figure out if I can adapt your code...
for i=1,50,1 do
Why specify three numbers? (Admittedly my syntax knowledge of 'for' is terrible...)
if otherTable[i].Job == "Shopkeep" do
'do' crashes the build. 'then' seems to work in it's place.
Apart from that, I'm still trying to troubleshoot getting this to work. That being said, I think that the widgets do not tolerate missing spaces in a table (ie: [1][2][3] are fine but [1][3][5] are not) so I guess I need to find another approach where I can fill all of the slots of the new table.
ie: if given this table;
1 2 3 | otherTable[1] = { name="Jim", Job="Hunter"} otherTable[2] = { name="Joe", Job="Drinker"} otherTable[3] = { name="Jed", Job="Drinker"} |
sorry that was a typo...
the for loop should have 3 numbers but last number will default to 1 if not given so it will work with 2 values also. 3rd value specify the increment.
ie if we give 2 it will increment by 2
1 2 3 | for 1=1,9,2 do print(i) end |
Yeah! That works. I had something similar but just couldn't get the [j]'s and [i]'s on the same page.
However, it had one major bug left which I just figured out. Nothing wrong with your code example, but something for anybody listening that wants to use widget.newTableView()
1. Using the above code you would now have newTable{}. But you can't tap anything without having an onRelease=command entry in each table ID!
2. Okay, so I'll just add the onRelease entry. Sorry! if you do this:
onRelease = PressingtheButton
..The table generator will just fill in nil as the entry. This means you need to have your onRelease function defined first. This is a problem, particularly because if you're developing anything on the iPad, that function NEEDs to know the table is there first. (I tried declaring the table first but that didn't seem to be enough.)
3. To get past these conflicting problems, you need to use this order:
a. Define the table
b. Define the onRelease function
c. Inject the onRelease entry into the table.
Example:
1 2 3 | for i=1,table.maxn(newTable) do newTable[i].onRelease = PressingtheButton end |
send message and call to a person
Forum: Report Spam + PM
[INSTALL_PARSE_FAILED_NO_CERTIFICATES]
[SOLVED] Director ERROR: Failed to execute new( params ) function on 'screen1'
Too many (200) local variables
Corona SVG Level Builder released. Drag and drop physics level editor with Inkscape and SVG.
Small bug in Collectible Items example
Pivot Joints and apparent elasticity
Can't make removeSelf() delayed
Why object pass through a line which is a static physics object
Zoom iPad simulator to actual size
Ball restart velocity and position
What is the bounds field in ui.newLabel
Game Center not on roadmap?
Disable INTERNET permissions?
just cannot get build enabled
unloadMe function in older Director Class
catapult like angry birds