Controlling order of events

OurJud
I'm just putting out feelers here, as I'm not entirely sure I'm going to take my game down this route as I need to consider if it will be too frustrating, but if I wanted different interactions with NPCs playing out differently depending on whether the player had done something else, how would I go about it?

If the player was tasked with investigating a murder, and needed to speak to two people to get information (let's call these people John and Bill), and you needed some piece of information from John, before Bill would give up his information, this would be done with a simple flag. Set the flag on John, and then check for that flag when he speaks to Bill. If player has the flag, Bill talks, if not he tells you nothing (not quite sure how you'd set this flag to determine the relevant dialogue exchanged had taken place, rather than the player just having visited the same location as John without actually speaking with him), but that's the principal.

But how would I do this if there were more than two NPC that you needed information from? Is there such a script as 'if player has [flagname1] and [flagname2], then...' ?

HegemonKhan
simpliest method is:

Integer Attribute Flags:

Global:

game.event_flag = 0
if (game.event_flag = 0) {
-> do script(s) 1
} else if (game.event_flag = 1) {
-> do script(s) 2
} else if (game.event_flag = 2) {
-> do script(s) 3
(.... etc.....)
} else if (game.event_flag = 100) {
-> do script(s) 101
}

and you can have more than just one such Integer Attribute Flag, of course:

game.event_flag = 0
game.dialogue_flag = 0
game.monster_level_flag = 0
game.item_drop_level_flag = 0
game.weather_flag = 0
etc etc etc

Locally:

Object: orc_1
orc_1.dialogue_flag = 0

Object: dragon_1
dragon_1.dialogue_flag = 0

Object: npc_1
npc_1.dialogue_flag = 0

Object: npc_2
npc_2.dialogue_flag = 0

------------------

Object: npc_1
Verb: talk:
if (npc_1.dialogue_flag = 0 and npc_2.dialogue_flag = 0) {
-> msg ("blah A")
} else if (npc_1.dialogue_flag = 1 and npc_2.dialogue_flag = 0) {
-> msg ("blah B")
} else if (npc_1.dialogue_flag = 0 and npc_2.dialogue_flag = 1) {
-> msg ("blah C")
} else if (npc_1.dialogue_flag = 1 and npc_2.dialogue_flag = 1) {
-> msg ("blah D")
} else if (npc_1.dialogue_flag = 2 and npc_2.dialogue_flag = 0) {
-> msg ("blah E")
}

Object: npc_2
Verb: talk:
if (npc_1.dialogue_flag = 0 and npc_2.dialogue_flag = 0) {
-> msg ("blah Z")
} else if (npc_1.dialogue_flag = 1 and npc_2.dialogue_flag = 0) {
-> msg ("blah Y")
} else if (npc_1.dialogue_flag = 0 and npc_2.dialogue_flag = 1) {
-> msg ("blah X")
} else if (npc_1.dialogue_flag = 1 and npc_2.dialogue_flag = 1) {
-> msg ("blah W")
} else if (npc_1.dialogue_flag = 2 and npc_2.dialogue_flag = 0) {
-> msg ("blah V ")
}

---------

or, the other alternative is using Lists and~or Dictionaries Attributes, as opposed to 'flag' Integer (or Boolean) Attributes.

OurJud
Thanks, HK. I'll need to study this and have a play around before it starts to click, but thanks :)

HegemonKhan
with Boolean Attributes, you're limited to only two cases: (1) false or (2) true, for your flags:
if (1:false), do this scripts1; else if (2:true), do this scripts2
examples:
game.killed_evil_wizard_boolean_flag = false -> true
game.acquired_dragon_slayer_sword_boolean_flag = false -> true
game.killed_dragon_boolean_flag = false -> true
game.rescued_princess_boolean_flag = false -> true

whereas....

with Integer Attributes, you've got an infinite number of cases: (1) 0, (2) 1, (3) 2, (4) 3, ... (101) 100 ... (100,000,000,001) 100,000,000,000 ... to infinity, and also in the negative value direction too: (5) -1, (6) -2, (7) -3, ... (100,000,001) -100,000,000 to negative infinity
if (y =0), do this scripts1; else if (y=1), do this scripts2; else if (y=2), do this scripts3; else if (y=3), do this scripts 4; etc etc etc

and the same with Lists~Dictionaries too, infinite cases for your flags

HegemonKhan
with dialogue (between two or more npcs), conceptually, you're doing: a '3 way handshake' (coding~programming), as you got to check on both (or all) of their states (flags), to determine what the response~output will be for that scenario of their states.

http://www.inetdaemon.com/tutorials/int ... hake.shtml

1. HK says (sends) 'hi' SYN to OJ
2. OJ says (sends) 'yes, I heard your "hi" to me' ACK to HK, and also OJ says (sends) 'hi' SYN to HK. Aka, a SYN-ACK is sent to HK.
(2.5. if OJ doesn't send the ACK to HK, then HK will resend his 'hi' SYN to OJ)
3. HK says (sends) 'yes, I heard your "hi" to me' ACK to OJ
(3.5. if HK doesn't send the ACK to OJ, then OJ will resend his 'hi' SYN to HK)
4. Greetings completed.

and we ourselves do this too, but our brains do it instantaneously, so we're completely unaware that we do communication exactly as how computers do communication, as there's ONLY 1 WAY to communicate, which is why humans and computers use the same method to communicate: it is the only method to communicate!

---------

here's an analogy example:

bob, bill, red shirts, blue shirts

how many combinations do we have?

1. bob:red and bill:blue
2. bob:red and bill:red
3. bob:blue and bill:red
4. bob:blue and bill:blue

if (bob:red and bill:red) {
-> msg (blah1)
} else if (bob:red and bill:blue) {
-> msg (blah2)
} else if (bob:blue and bill:red) {
-> msg ("blah3)
} else if (bob:blue and bill:blue) {
-> msg ("blah4")
}

---------------

npc1 = bob
npc2 = bill
red shirt = 0
blue shirt = 1

if (npc1.shirt = 0 and npc2.shirt = 0) {
-> msg ("blah1")
} else if (npc1.shirt = 0 and npc2.shirt = 1) {
-> msg ("blah2")
} else if (npc1.shirt = 1 and npc2.shirt = 0) {
-> msg ("blah3")
} else if (npc1.shirt = 1 and npc2.shirt = 1) {
-> msg ("blah1")
}

-------------

bill.dialogue = 0
bob.dialogue = 0

Bill:
Verb: talk
if (bill.dialogue = 0 and bob.dialogue = 0) {
-> msg ("Hi, I'm Bill. Go say hi to my friend Bob.")
-> bill.dialogue = 1
} else if (bill.dialogue = 0 and bob.dialogue = 1) {
-> msg ("Hi, I'm Bill. I see you already met my friend, Bob.")
-> bill.dialogue = 1
} else if (bill.dialogue = 1 and bob.dialogue = 0) {
-> msg ("Go say hi to my friend bob.")
} else if (bill.dialogue = 1 and bob.dialogue = 1) {
-> msg ("Go say goodbye to my friend, bob.")
-> bill.dialogue = 2
} else if (bill.dialogue = 2 and bob.dialogue = 1) {
-> msg ("Again, Go say goodbye to my friend, bob.")
} else if (bill.dialogue = 2 and bob.dialogue = 2) {
-> msg ("You've won the game!")
-> finish
}

Bob:
Verb: talk
if (bill.dialogue = 0 and bob.dialogue = 0) {
-> msg ("Hi, I'm Bob. Go say hi to my friend bill.")
-> bob.dialogue = 1
} else if (bill.dialogue = 0 and bob.dialogue = 1) {
-> msg ("Go say hi to my friend Bill.")
} else if (bill.dialogue = 1 and bob.dialogue = 0) {
-> msg ("Hi, I'm Bob. I see you already met my friend, Bill.")
-> bob.dialogue = 1
} else if (bill.dialogue = 1 and bob.dialogue = 1) {
-> msg ("Go say goodbye to my friend, bill.")
-> bob.dialogue = 2
} else if (bill.dialogue = 1 and bob.dialogue = 2) {
-> msg ("Again, Go say goodbye to my friend, bill.")
} else if (bill.dialogue = 2 and bob.dialogue = 2) {
-> msg ("You've won the game!")
-> finish

The Pixie
OurJud wrote:I'm just putting out feelers here, as I'm not entirely sure I'm going to take my game down this route as I need to consider if it will be too frustrating, but if I wanted different interactions with NPCs playing out differently depending on whether the player had done something else, how would I go about it?

If the player was tasked with investigating a murder, and needed to speak to two people to get information (let's call these people John and Bill), and you needed some piece of information from John, before Bill would give up his information, this would be done with a simple flag. Set the flag on John, and then check for that flag when he speaks to Bill. If player has the flag, Bill talks, if not he tells you nothing (not quite sure how you'd set this flag to determine the relevant dialogue exchanged had taken place, rather than the player just having visited the same location as John without actually speaking with him), but that's the principal.

But how would I do this if there were more than two NPC that you needed information from? Is there such a script as 'if player has [flagname1] and [flagname2], then...' ?

The simplest way is to have the flags on Bill and John (set a Boolean attribute on both of them, perhaps called flag).

In the conversation you set the flags:
msg("'Who did it?'")
msg("'It was John, I saw him!'")
bill.flag = true


When talking to John, check if Bill has the flag set:
if (bill.flag) {
msg("'I know you did it, Bill saw you.'")
msg("'Okay, okay, I confess.'")
john.flag = true
}
else {
msg("'Did you do it?'")
msg("'You can't prove anything.'")
}


To test if both have been set:
if (bill.flag and john.flag) {
msg("'I've blown the case wide open, boss!'")
}
else if (bill.flag) {
msg("'I've think I've got a witness boss.'")
}
else {
msg("'Still looking for leads here, boss.'")
}

OurJud
Thanks, TP. I need to work out how to apply this pattern to more than just the two NPCs, but at least I have the bones of it now.

This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums