Page 1 of 1

dsb_export and importable archs

Posted: Sun Feb 16, 2014 7:51 am
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.

Re: dsb_export and importable archs

Posted: Mon Feb 17, 2014 4:54 am
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.

Re: dsb_export and importable archs

Posted: Mon Feb 17, 2014 3:14 pm
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"

Re: dsb_export and importable archs

Posted: Mon Feb 17, 2014 9:24 pm
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.

Re: dsb_export and importable archs

Posted: Tue Feb 18, 2014 1:59 am
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.

Re: dsb_export and importable archs

Posted: Tue Feb 18, 2014 2:56 am
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.

Re: dsb_export and importable archs

Posted: Tue Feb 18, 2014 2:15 pm
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-)