Page 1 of 1
Query the total number of available champions and loop
Posted: Sun May 06, 2012 3:18 pm
by Gambit37
I want to create some loops to iterate over the full list of champions that are available in the dungeon (prior to the player choosing any).
How would I do this? Is there a global champion array that I can access? I'm looking to do various things in this loop, including setting up some gfx, eg
Code: Select all
for i=1,table.getn(global_champion_array) do
gfx["bigpic_" .. global_champion_array[i].champion_name)]
end
Obviously I'm guessing at the array name and key names! Anyway, is this possible?
Re: Query the total number of available champions and loop
Posted: Sun May 06, 2012 8:43 pm
by Sophia
At present, there's no centrally maintained list of champion indices.
However, ultimately, they are just id numbers. So, you could always look at your dungeon.lua and extract the id numbers.
Look at the first parameter to calls to dsb_add_champion, which should be grouped together.
Re: Query the total number of available champions and loop
Posted: Sun May 06, 2012 8:49 pm
by Gambit37
Ah, right, that's no better than the hardcoding I've currently got so I'll leave it as it is.
Is there an internal total of champions that have been created? That would be just as good. Otherwise I have to hardcode the loop limits, and adding more champions breaks the loop. I was just looking for a way of making the whole thing automatic, so that I could write the code once, then add as many champions as I wanted without having to edit the code again. 'Cos I keep forgetting to edit it

Re: Query the total number of available champions and loop
Posted: Sun May 06, 2012 9:23 pm
by Sophia
No, sorry.

Re: Query the total number of available champions and loop
Posted: Sun May 06, 2012 9:25 pm
by Gambit37
No worries, thanks anyway

Re: Query the total number of available champions and loop
Posted: Sun May 06, 2012 9:58 pm
by Gambit37
So here's my now trying to do the loop I described by setting the total champions in a var:
Code: Select all
-- Setup champion array and graphics
path = pathimg .. "champions/"
champions_total = 12
for s = 1, champions_total do
-- Set current champion name
c_name = dsb_get_charname(s)
-- Put current champion in array
champions[s] = {
shortname = c_name,
selected = false
}
-- Create graphics entries
gfx["c_pic_" .. c_name] = dsb_get_bitmap(path .. "pic_" .. c_name)
gfx["c_text_" .. c_name] = dsb_get_bitmap(path .. "text_" .. c_name)
gfx["port_" .. c_name] = dsb_get_bitmap(path .. "post_" .. c_name)
end
This is some new code I'm creating so that I don't have to hardcode my champions table by hand. But it doesn't work because this bit doesn't work:
Code: Select all
for s = 1, champions_total do
-- Set current champion name
c_name = dsb_get_charname(s)
DSB complains of "FATAL LUA ERROR: select-champions.lua:16: Invalid character index 1". So for some reason
dsb_get_charname(s) is not working...?
Is this because the dungeon.lua hasn't been parsed yet? (I'm doing this in a file that's loaded in my manifest).
Re: Query the total number of available champions and loop
Posted: Mon May 07, 2012 4:04 am
by Sophia
Gambit37 wrote:DSB complains of "FATAL LUA ERROR: select-champions.lua:16: Invalid character index 1". So for some reason dsb_get_charname(s) is not working...?
Is this because the dungeon.lua hasn't been parsed yet? (I'm doing this in a file that's loaded in my manifest).
That's correct.
I'm afraid you've gotten a little too clever for DSB.

There really is no way around this. You'll have to pull the filenames from a hardcoded table.

Re: Query the total number of available champions and loop
Posted: Mon May 07, 2012 4:26 am
by Gambit37
Sophia wrote:I'm afraid you've gotten a little too clever for DSB.

WHOOOAA! I'm printing that out in 256pt type and sticking it on my wall!!!!
Sophia wrote:There really is no way around this. You'll have to pull the filenames from a hardcoded table.

No worries, I created a table of the champions first names and now iterate over that instead, I can use that to build all filenames. It's pretty much like I had before, but the code is quite reduced now, so it's better optimised. (Before I was writing out all the gfx. identifers manually in full....)