Multiple triggers

Z7-852
06 Feb 2012, 09:16
In my game there are 6 NPC and all have common attribute (lets call it fate) and another attribute called fatetrigger (ie. NPC1.fate = 3 and NPC1.fatetrigger = false)

I want that when some NPC fate gets to 10 it will trigger a script and set fatetrigger to true. This I know how to do. But I also want to trigger the script after certain time limit (lets say 10 minutes of game play). Then I want to check which NPC has a highest fate and trigger right script.

I could do this by writing "If NPC1.fate > NPC2.fate and NPC1.fate > NPC2.fate and so on" then I would have to duplicate this six times. And again six times untill all fates have been activated. Also I don't want to trigger any fate twice (so if someone already has attribute "fatetrigger = true" they should not be included in the comparison.

And when lastly when all six "NPC.fatetrigger = true " I want to end the game. So there is 60 minute time limit to the game.

What is the easiest way to do this whole thing?

Pertex
06 Feb 2012, 20:18
I do not understand exactly what you want to do, but look at the function checktrigger in the appended file. It checks all object if they have the attribute fatetrigger. If yes and the attrib is true it increases a counter. If the counter is equal to the number of NPCs, it finishes the game. If the attrib is false it compares the fate with the last found value. If it is greater it saves this value. After the loop you have the object with the maximum fate and you can call another function

Z7-852
07 Feb 2012, 07:02
Is there any other way to do this execpt with a loop? Let me try to be more clear.
I have 6 NPC with all have 2 attributes called fate (ie. NPC1.fate) that have numeric value. Then each NPC have attribute fatetrigger that is boolean (so true/false) that tells if they have met their fate.
Player has attribute wake that is also numeric value and modified by lot of things in the game. Most importantly there is timer that substracts one from wake each minute. At some point wake will hit zero. And here I have a problem.

I want to know which NPC has a highest fate (ie. NPC1.fate = 4 ; NPC2.fate = 8 ; NPC3.fate = 2 ; NPC4.fate = 4 and so on).
No NPC2 have the highest fate value. I want to then run a script (that playes message and chance NPC2.fatetrigger to true).
So I need some kind of comparison that tells me which NPC has a highest fate and activates correct script.

But not to make things simple. If NPC.fatetrigger = true that NPC should not be included in comparison so the same fate is not triggered twice.

Pertex
07 Feb 2012, 07:43
Without a loop? Yes, its possible, but not good code. In germany we call it spaghetti code.
So, I changed the function a bit, so it should do what you want it to do:


<function name="checktrigger"><![CDATA[
nrNPC = 6
counter = 0
maxfate = 0
maxobj = null
foreach (obj, AllObjects()) {
x = HasAttribute ( obj , "fatetrigger" )
if ( x ) {
if (GetBoolean (obj , "fatetrigger" )) {
counter = counter+1
}
else {
if (obj.fate>=maxfate) {
maxfate = obj.fate
maxobj = obj
}
}
}
}
if ( not null = maxobj ){
msg("Here is a message")
maxobj.fatetrigger = true
}
if (counter=nrNPC) {
finish
}
]]></function>

Z7-852
07 Feb 2012, 07:54
So it's better to use the loop you gave earlier?
I havent tested it yet (the quest is on my laptop) but if it does what I want I thank you.
I havent really used any coding language in 5 years so I'am bit rusty. Luckily Quest is easy to use without any coding knowladge.

Z7-852
07 Feb 2012, 12:09
I tried the code you gave me but it doesn't work.
Also it doesn't allow me me print right message when fate is triggered.
If you would be so kind I could send the game to you and you could then see what I need do to make this work.
I love textadventures and making them but as I said before I really don't have much coding experience.

Pertex
07 Feb 2012, 13:16
you got a pm