dsb_export and importable archs

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
kaypy
Artisan
Posts: 171
Joined: Sun Jan 19, 2014 7:11 am

dsb_export and importable archs

Post by kaypy »

How hard would it be to make dsb_export available in importable arch scripts?

I was trying to make the complete darc armour have an anti-light aura, but copying the illumulet code requires that I have a global variable for it.
Friends don't let friends eat worm round
User avatar
Sophia
Concise and Honest
Posts: 4239
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Re: dsb_export and importable archs

Post by Sophia »

The illumulet code was written fairly early in DSB's development and, realistically, it's actually not a very good model for how to do what it does.

You could use a ch_exvar that you iterate over the party and check for; it would add very little code and not require a global variable.
kaypy
Artisan
Posts: 171
Joined: Sun Jan 19, 2014 7:11 am

Re: dsb_export and importable archs

Post by kaypy »

Hmm. I don't know that in general I can guarantee the existence of any particular champion, and I don't seem to have any way to iterate over them easily. I think this approach is getting hairy, fast.

Hmm. There are always... other... approaches...

Code: Select all

--[[
	A construct released upon the world by a gang of four sages.
	For something supposedly unique, it is spotted feasting on the
	brains of apprentice programmers with surprising frequency.
]]
obj.singleton = {
	type="FLOORFLAT",
	class="MECHANISM",
	get_instance=function(self)
		if (self.instance ~= nil
			and dsb_valid_inst(self.instance)
			and dsb_find_arch(self.instance) == self) then
			return self.instance
		end
		for id in dsb_insts() do
			local arch = dsb_find_arch(id)
			if (arch == self) then
				self.instance = id
				return id
			end
		end
		self.instance = dsb_spawn(self,LIMBO,0,0,0)
		exvar[self.instance]={}
		return self.instance
	end
}
edit: ok, that should "work"
Last edited by kaypy on Tue Feb 18, 2014 2:25 pm, edited 1 time in total.
Friends don't let friends eat worm round
User avatar
Sophia
Concise and Honest
Posts: 4239
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Re: dsb_export and importable archs

Post by Sophia »

I wouldn't recommend doing that. :shock:

Anyway, here's an easier way to do what you want:

Code: Select all

function check_party_for_ch_exvar(varname)
   for pp=0,3 do
      local who = dsb_ppos_char(pp)
      if (valid_and_alive(who)) then
         if (ch_exvar[who] and ch_exvar[who][varname]) then return true end
      end
   end
   return false
end
Then you can just set a ch_exvar called "darc" or whatever when someone suits up.
kaypy
Artisan
Posts: 171
Joined: Sun Jan 19, 2014 7:11 am

Re: dsb_export and importable archs

Post by kaypy »

Sophia wrote:I wouldn't recommend doing that. :shock:
It was (mostly) tongue in cheek. (Some of it may live on to simplify my lighting code elsewhere...)
Anyway, here's an easier way to do what you want:
Ah yes. I was still thinking in terms of "where do I store this value I have?" instead of "do I need this value?". Thanks.

Still leaves the question of what to do if I really do need global state, but it's probably for the best if globals are awkward and cumbersome to use.
Friends don't let friends eat worm round
User avatar
Sophia
Concise and Honest
Posts: 4239
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Re: dsb_export and importable archs

Post by Sophia »

The "singleton" object as you implemented it there is kind of messy and I'm not even sure it would work. However, I was really just objecting to that one object, so to speak. The core premise behind it, creating object instances and using them to store state information, is far from the worst idea, and it is used elsewhere in DSB's base code. (e.g., the light_controller and shield_controller)

So, yes, if you really do need to store something accessible globally, I'd actually recommend that approach. You can remember its id number by storing that in some other inst's exvar, some character's ch_exvar, or simply by iterating over the global list of insts and finding all of them of the type you want.
kaypy
Artisan
Posts: 171
Joined: Sun Jan 19, 2014 7:11 am

Re: dsb_export and importable archs

Post by kaypy »

Oh, I see- the variables aren't preserved across sessions, but they also aren't flushed when reloading saves either.

Hmm. I wonder if you could use that to torment players for dying in previous sessions...

edit: OK, I think it should now be merely be a bad idea rather than actually broken 8-)
Friends don't let friends eat worm round
Post Reply