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.
dsb_export and importable archs
Moderator: Sophia
Forum rules
Please read the Forum rules and policies before posting.
Please read the Forum rules and policies before posting.
- Sophia
- Concise and Honest
- Posts: 4240
- Joined: Thu Sep 12, 2002 9:50 pm
- Location: Nowhere in particular
- Contact:
Re: dsb_export and importable archs
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.
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
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...
edit: ok, that should "work"
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
}
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
- Sophia
- Concise and Honest
- Posts: 4240
- Joined: Thu Sep 12, 2002 9:50 pm
- Location: Nowhere in particular
- Contact:
Re: dsb_export and importable archs
I wouldn't recommend doing that.
Anyway, here's an easier way to do what you want:
Then you can just set a ch_exvar called "darc" or whatever when someone suits up.
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
Re: dsb_export and importable archs
It was (mostly) tongue in cheek. (Some of it may live on to simplify my lighting code elsewhere...)Sophia wrote:I wouldn't recommend doing that. :shock:
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.Anyway, here's an easier way to do what you want:
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
- Sophia
- Concise and Honest
- Posts: 4240
- Joined: Thu Sep 12, 2002 9:50 pm
- Location: Nowhere in particular
- Contact:
Re: dsb_export and importable archs
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.
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
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-)
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