Query the total number of available champions and loop

This forum is for the Lua scriptable clone of DM/CSB called Dungeon Strikes Back by Sophia. Use DSB to build your own highly customised games.

Moderator: Sophia

Forum rules
Please read the Forum rules and policies before posting.
Post Reply
User avatar
Gambit37
Should eat more pies
Posts: 13714
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Query the total number of available champions and loop

Post 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?
User avatar
Sophia
Concise and Honest
Posts: 4239
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Re: Query the total number of available champions and loop

Post 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.
User avatar
Gambit37
Should eat more pies
Posts: 13714
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: Query the total number of available champions and loop

Post 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 ;-)
User avatar
Sophia
Concise and Honest
Posts: 4239
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Re: Query the total number of available champions and loop

Post by Sophia »

No, sorry. :(
User avatar
Gambit37
Should eat more pies
Posts: 13714
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: Query the total number of available champions and loop

Post by Gambit37 »

No worries, thanks anyway :)
User avatar
Gambit37
Should eat more pies
Posts: 13714
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: Query the total number of available champions and loop

Post 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).
User avatar
Sophia
Concise and Honest
Posts: 4239
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Re: Query the total number of available champions and loop

Post 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. :(
User avatar
Gambit37
Should eat more pies
Posts: 13714
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: Query the total number of available champions and loop

Post 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!!!! :mrgreen:
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....)
Post Reply