Referring to characters in a script?
Referring to characters in a script?
Something simple I'd like to be able to do, but that I haven't figured out with the Dungeon Editor yet, is how I could single out a character in the player's party at the beginning of the game so that I can I refer to that particular character (rather than a character slot) in later scripts. I'd also like to do something similar to reference a character uses a particular item. Any help?
Re: Referring to characters in a script?
The big friendly warden does this somewhat, calling you by name depending on your character names and positions
Finished Dungeons - complete mods to play
Re: Referring to characters in a script?
The character ordinal value is what you need... when the party is generated each character is given an ordinal value from 1 to 4 (different to the slot value)... this value never changes, even if you move the characters around.
so you could randomly generate an ordinal value at the start of the game and whenever you need to refer to that champion, use the following script to find the champion entity based on that ordinal.
regarding your item use question you can use party:getChampion(slot):getOrdinal() to find the ordinal value of the champion in a particular slot at the time... or if it's part of an onUse() item hook you can do
so you could randomly generate an ordinal value at the start of the game and whenever you need to refer to that champion, use the following script to find the champion entity based on that ordinal.
Code: Select all
function findChampionByOrdinal(ord)
for ch = 1,4 do
if party:getChampion(ch):getOrdinal() == ord then
return party:getChampion(ch)
end
end
endregarding your item use question you can use party:getChampion(slot):getOrdinal() to find the ordinal value of the champion in a particular slot at the time... or if it's part of an onUse() item hook you can do
Code: Select all
onUse() = function(item,champion)
local item_user_ordinal = champion:getOrdinal()
DO OTHER STUFF
endPuzzle Frameworks - http://www.grimrock.net/forum/viewtopic.php?f=14&t=4564
Magic Pack - https://www.nexusmods.com/grimrock/mods/70
Area of Effect Spell System - http://www.grimrock.net/forum/viewtopic ... 150#p44382
Magic Pack - https://www.nexusmods.com/grimrock/mods/70
Area of Effect Spell System - http://www.grimrock.net/forum/viewtopic ... 150#p44382
Re: Referring to characters in a script?
Thanks, guys! I'll get these worked into my game when I get a minute and report back if I have any trouble.
Re: Referring to characters in a script?
I had a go at this today. I'm having difficulty referring to a character who has used an item in a later script. How is this done with a local variable?
A friend advised I try defining that character's ordinal position as a global variable called "servOrd", but this doesn't seem to work. When I attempt to reference "servOrd" in the second script, nothing happens. If I try to get it to hudPrint an ordinal referring to servOrd, I end up with an error message.
onUseItem hook:
Function attempting to reference the same ordinal character later:
A friend advised I try defining that character's ordinal position as a global variable called "servOrd", but this doesn't seem to work. When I attempt to reference "servOrd" in the second script, nothing happens. If I try to get it to hudPrint an ordinal referring to servOrd, I end up with an error message.
onUseItem hook:
SpoilerShow
Code: Select all
onUseItem = function(self, champion)
party:shakeCamera(0.6, 2)
playSound("game_over")
champion:addSkillPoints(5)
servOrd = champion:getOrdinal()
hudPrint(servOrd.." is servOrd")
return true
end,
SpoilerShow
Code: Select all
function nauseate()
--hudPrint(servOrd.." is servOrd") <-- attempt to concatenate global 'servOrd' (a nil value)
for ch = 1,4 do
if party:getChampion(ch):getOrdinal() == 1 then
party:getChampion(ch):setCondition("diseased", 90001)
end
if party:getChampion(ch):getOrdinal() == servOrd then
party:getChampion(ch):setCondition("diseased", 90001)
end
end
endRe: Referring to characters in a script?
You can't save stuff in the external lua files (I think). If you want to define a variable to use later, put the info in a script in the dungeon. If you need it to happen from a hook, then just reference that script to do a function that sets the variable:
in your items.lua file:
in a script entity in the dungeon called myItemScript:
in your other script and function:
You could put the function right near your nauseate function, and then would not need the script name first (so it would look like you originally had it), but you would then need to change the hook reference to the correct script name.
in your items.lua file:
Code: Select all
onUseItem = function(self, champion)
party:shakeCamera(0.6, 2)
playSound("game_over")
champion:addSkillPoints(5)
myItemScript.setServOrd(champion)
hudPrint(servOrd.." is servOrd")
return true
end,Code: Select all
servOrd = 0
function setServOrd(champion)
servOrd = champion:getOrdinal()
endCode: Select all
function nauseate()
--hudPrint(myItemScript.servOrd.." is servOrd") <-- attempt to concatenate global 'servOrd' (a nil value)
for ch = 1,4 do
if party:getChampion(ch):getOrdinal() == 1 then
party:getChampion(ch):setCondition("diseased", 90001)
end
if party:getChampion(ch):getOrdinal() == servOrd then
party:getChampion(ch):setCondition("diseased", 90001)
end
end
endFinished Dungeons - complete mods to play
