Dialogue exchange not working

OurJud
26 Nov 2014, 01:50
Can anyone confident with coding have a look over this and tell me where I'm going wrong.

The desired sequence should go as follows:

You are in a room and told of an exit leading north to a place called 'backroom'. You are also told there is a man called Tom here.

Tom will ask you for a name and here the game waits for three inputs.

1. Answer correctly and he asks you a second question.
2. Answer incorrectly and he tells you to get lost.
3. Try to go north without answering, and he grabs you by the shirt and insists you answer the question.

If you answer correctly, the second question is asked, and the first sequence is repeated, except this time a correct answer will 'move' the player to the 'backroom'.

When I play test this and try to go north without answering the question, I get the desired response, but then even answering the question correctly I'm told to get lost.

Basically, the only way I can get this to run logically, is if I answer both questions correctly from the start. None of the alternative possibilities run correctly.

This is the script:

msg ("This is a test room. There is a man called Tom here.<br/>")
SetTimeout (3) {
msg ("Tom turns to look at you. \"I sincerely hope you've got some information for me,\" he says. \"Who sent you?\"<br/>")
}
get input {
if (result="terry jones") {
msg ("The man leans forward and grins menacingly. \"Good, good. And did he give you the number?\"<br/>")
}
else if (result="n") {
msg ("\"Whooa!!\" Tom jumps from his chair and grabs you by the chest. \"Where d'you think you're going? Answer the God-damn question first!\"<br/>")
if (result="terry jones") {
msg ("The man leans forward and grins menacingly. \"Good, good. And did he give you the number?\"<br/>")
if (result="1068") {
msg ("He studies you for a while, giving no clue as to if you've told him what he wanted to hear. Eventually he relaxes back in his chair and waves you through to the back room with a nod of his head.<br/>")
}
}
}
else {
msg ("The man grabs his gun and points it at your head. \"In three seconds time I'm going to pull the trigger. Get out of here now!\"<br/>")
}
get input {
if (result="1068") {
msg ("He studies you for a while, giving no clue as to if you've told him what he wanted to hear. Eventually he relaxes back in his chair and waves you through to the back room with a nod of his head.<br/>")
}
else {
msg ("The man grabs his gun and points it at your head. \"In three seconds time I'm going to pull the trigger. Get out of here now!\"")
}
}
}

HegemonKhan
26 Nov 2014, 04:47
you almost have it right, just a little out of order though, here's my corrections of your code:

msg ("This is a test room. There is a man called Tom here.<br/>")
SetTimeoutID (3, "timer_1") {
DisableTimer (timer_1) // if the Timer's following scripts don't run, this code line needs to go at the end of the scripting
msg ("Tom turns to look at you. \"I sincerely hope you've got some information for me,\" he says. \"Who sent you?\"<br/>")
get input {
if (result="terry jones") {
msg ("The man leans forward and grins menacingly. \"Good, good. And did he give you the number?\"<br/>")
get input {
if (result="1068") {
msg ("He studies you for a while, giving no clue as to if you've told him what he wanted to hear. Eventually he relaxes back in his chair and waves you through to the back room with a nod of his head.<br/>")
} else {
msg ("The man grabs his gun and points it at your head. \"In three seconds time I'm going to pull the trigger. Get out of here now!\"")
}
}
} else if (result="n") {
msg ("\"Whooa!!\" Tom jumps from his chair and grabs you by the chest. \"Where d'you think you're going? Answer the God-damn question first!\"<br/>")
get input {
if (result="terry jones") {
msg ("The man leans forward and grins menacingly. \"Good, good. And did he give you the number?\"<br/>")
get input {
if (result="1068") {
msg ("He studies you for a while, giving no clue as to if you've told him what he wanted to hear. Eventually he relaxes back in his chair and waves you through to the back room with a nod of his head.<br/>")
} else {
msg ("The man grabs his gun and points it at your head. \"In three seconds time I'm going to pull the trigger. Get out of here now!\"<br/>")
}
}
}
}
}
}
}


now, you probably notice the redundency of your code, we can "clean" up your code, to make it less reduntant, but I'll let you try first, if you want to.

otherwise, we can certainly leave it as is too (it doesn't cause any issues), or I can clean it up for you.

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

here's what was wrong with your code, I'm going to put it into an outline, to help explain it's errors of logical ordering (order of operations) heirarchy:

I. msg ("This is a test room. There is a man called Tom here.<br/>")
II. SetTimeout (3) {
A. msg ("Tom turns to look at you. \"I sincerely hope you've got some information for me,\" he says. \"Who sent you?\"<br/>")
III. }
// your 'get input' below is going to execute as you wait for the 3 seconds to pass for the display of the 'msg' Script (and it'll be displaying that 'msg' EVERY 3 seconds too): big issues!
IV. get input {
A. if (result="terry jones") {
1. msg ("The man leans forward and grins menacingly. \"Good, good. And did he give you the number?\"<br/>")
// this never gets to your 'if (result = 1068)', as there's no logic-order-heirarchy connection~path to it, as 'B.' is in the way, ending A.).
B. } else if (result="n") {
1. msg ("\"Whooa!!\" Tom jumps from his chair and grabs you by the chest. \"Where d'you think you're going? Answer the God-damn question first!\"<br/>")
// you got no 'get input' for your below (2.) checking of an input. As it stands without the 'get input', this is the il-logic that you got:
// if (not result = "terry jones"), then... yet if (result = "terry jones"), then do 'msg' [ '1)' ]. That makes no sense: if "no", yet if "yes", then do X. "No" is not "yes".
2. if (result="terry jones") {
a. msg ("The man leans forward and grins menacingly. \"Good, good. And did he give you the number?\"<br/>")
// no 'get input' for the checking of an input below (b.)
b. if (result="1068") {
1) msg ("He studies you for a while, giving no clue as to if you've told him what he wanted to hear. Eventually he relaxes back in his chair and waves you through to the back room with a nod of his head.<br/>")
c. }
3. }
C. } else {
1. msg ("The man grabs his gun and points it at your head. \"In three seconds time I'm going to pull the trigger. Get out of here now!\"<br/>")
D. }
// the below (E.) is not connected to it's beginning part (A.) in any way what-so-ever.
E. get input {
1. if (result="1068") {
a. msg ("He studies you for a while, giving no clue as to if you've told him what he wanted to hear. Eventually he relaxes back in his chair and waves you through to the back room with a nod of his head.<br/>")
2. } else {
a. msg ("The man grabs his gun and points it at your head. \"In three seconds time I'm going to pull the trigger. Get out of here now!\"")
3. }
F. }
V. }


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

additional order heirarchy:

ONE
-> TWO
THREE

TWO and THREE are executing at the same time, so you got to be careful.

ONE
|...\
|....TWO
|
THREE

there's two paths (the lines) from ONE, hence TWO and THREE executing at the same time.

The Pixie
26 Nov 2014, 09:05
This is not straightforward... First the time delay.

SetTimeout (3) {
if (player.parent = room5) {
msg ("Tom shoots you")
finish
}
}
msg ("This is a test room. There is a man called Tom here.<br/>")
msg ("The man grabs his gun and points it at your head. \"In three seconds time I'm going to pull the trigger. Get out of here now!\"")


SetTimeout has a script that is run after the delay. However, everything after that will happen straightaway, so the player sees the messages in the last two lines at once.

The script checks if the player is still in the room (which was called room5 in my test; you cannot use "this" within the SetTimeout script), and if she is, she gets shot.



Where d'you think you're going?

This sounds like it should be on the exit (the one the player came through, I guess). I would put a Boolean attribute on the exit from the room called "blocked", then on the Exit tab, tick the "Run a script" box. The script could be:

if (this.blocked) {
msg ("\"Whooa!!\" Tom jumps from his chair and grabs you by the chest. \"Where d'you think you're going? Answer the God-damn question first!\"<br/>")
}
else {
player.parent = this.to
}

If the blocked attribute is set to true, the player sees a message, otherwise she gets moved to the proper room as normal.



On to asking questions

The input command works like SetTimeout - the script is run only when the player has typed something. You need two for two questions, one inside the other. Also note that result is put in lower case as the player could type "Terry Jones".

msg ("Tom turns to look at you. \"I sincerely hope you've got some information for me,\" he says. \"Who sent you?\"<br/>")
get input {
if (LCase(result)="terry jones") {
msg ("The man leans forward and grins menacingly. \"Good, good. And did he give you the number?\"<br/>")
get input {
if (result="1068") {
msg ("He studies you for a while, giving no clue as to if you've told him what he wanted to hear. Eventually he relaxes back in his chair and waves you through to the back room with a nod of his head.<br/>")
}
else {
SetTimeout (3) {
if (player.parent = room5) {
msg ("Tom shoots you")
finish
}
}
msg ("The man grabs his gun and points it at your head. \"In three seconds time I'm going to pull the trigger. Get out of here now!\"")
}
}
}
else {
SetTimeout (3) {
if (player.parent = room5) {
msg ("Tom shoots you")
finish
}
}
msg ("The man grabs his gun and points it at your head. \"In three seconds time I'm going to pull the trigger. Get out of here now!\"")
}
}


Now that I have done that, I am not sure when the exit is blocked... Hmm, this may not be quite what you want, but hopefully gets you going in the right direction.

jaynabonne
26 Nov 2014, 12:33
HK, SetTimeout is a one-shot thing. It will not recur. You don't need to disable it or anything like that. if you want a recurring event, you need to create a proper timer.

OurJud
26 Nov 2014, 17:24
Mmm...

HK, your script certainly worked better than mine - in that it would allow you to answer after trying to go north in the first instance, but there are still lots of ways you can break the logic of the scene.

TP, as you say yourself, it's not straightforward and your method also has a couple of issues that need resolving. I'm not sure I'm at that level yet, but I can only keep trying.

In a nutshell, I need it to run smoothly but also cover all possibilities.

Scenario 1: Answer both questions correctly from the beginning of the sequence and you successfully gain access to the back room.

Scenario 2: Try to move north at ANY point before the two questions are answered, Tom grabs you and insists you answer the question (try this twice and he threatens you, telling you to get lost)

Scenario 3: Answer incorrectly at any point, Tom threatens you and tells you to get lost.

The more I think about this, the less inclined I am to think I can pull it off. There are just too many things the player might do during a scene like this. They may realise they don't have the name and want to leave (triggering the wrong answer sequence). They may try to to pull out their own gun (again triggering the wrong answer sequence).

I think I need to go back to the drawing board and simplify matters. Maybe just have one question.

jaynabonne
26 Nov 2014, 17:46
I personally would not conflate answering the questions with trying to move north. It would either be in the "question has been asked and waiting an answer" state, using "get input" or in the "I'm letting Quest parse things as usual" outside the "get input". If Tom asks a question and you respond "n", it should be the same as any other wrong answer. It seems like it would be less confusing for the player as well.

Just my take. :)

OurJud
26 Nov 2014, 17:55
jaynabonne wrote:I personally would not conflate answering the questions with trying to move north. It would either be in the "question has been asked and waiting an answer" state, using "get input" or in the "I'm letting Quest parse things as usual" outside the "get input". If Tom asks a question and you respond "n", it should be the same as any other wrong answer. It seems like it would be less confusing for the player as well.

Just my take. :)


Yes, I sometimes forget the traditions of TA.

I just wrote a small tree that might help me simplify the scene:

"Who sent you?"

Correct answer = access to the backroom

Wrong answer = "get lost"

Any other input = Grabbed by Tom's henchmen and thrown out, possibly losing weapon in the process (although I don't know how I'd script the gun losing thing)

HegemonKhan
26 Nov 2014, 18:50
I (and Jay and Pixie) can certainly help you deal with all of the logic checks for the various scenarios, though in my previous post, I was just fixing up what you had coded, as close as I could to keeping it how you had it coded. I wasn't adding in all the additional logic checks that you desire for it in that previous post of mine. I've gotten pretty good at doing those logic checks now (see my combat code for example), hehe.

enemy = GetObject (text)
if (enemy = null) {
foreach (object_x,AllObjects()) {
if (object_x.alias=text) {
enemy = object_x
}
}
}
if (enemy = null) {
msg ("There is no " + text + " here.")
}
else if (not Doesinherit (enemy,"npc")) {
msg ("You can not battle that!")
}
else if (not npc_reachable (enemy)) {
msg ("There is no " + enemy.alias + " in your vicinity.")
}
else if (GetBoolean (enemy,"dead") = true) {
msg (enemy.alias + " is already dead.")
}
else if (GetBoolean (enemy,"hostile") = false) {
msg (enemy.alias + " is not hostile.")
}
else if (battle_sequence (self,enemy) = true) {
msg ("The battle is over.")
} else {
// fight~combat scripting blocks
}

// and:

switch (result) {
case ("Attack") {
value_x = false
if (RandomChance (GetInt (enemy,"agi") - GetInt (self,"spd")) = true) {
msg (enemy.alias + "evaded your attack!")
value_x = true
}
else if (RandomChance (GetInt (enemy,"Dex") - GetInt (self,"agi")) = true) {
msg (enemy.alias + "parried your attack!")
value_x = true
}
else if (RandomChance (GetInt (enemy,"agi") - GetInt (self,"dex")) = true) {
msg (enemy.alias + "blocked your attack!")
value_x = true
}
else if (RandomChance (GetInt (self,"dex") - GetInt (enemy,"spd")) = false) {
msg ("Your attack missed " + enemy.alias +"!")
value_x = true
}
else if (RandomChance (GetInt (enemy,"physical_resistance") - GetInt (self,"hit_chance")) = true) {
msg ("Your attack got resisted by " + enemy.alias +"!")
value_x = true
}
if (value_x = false) {
// you damaging the enemy scripting blocks
} else if (value_x = true) {
// the enemy's combat~fight turn scripting blocks
}


and:

<function name="birth_year_function"><![CDATA[
-> msg ("What year were you born?")
-> get input {
->-> if (IsNumeric (result) = false) {
->->-> ClearScreen
->->-> msg ("Please type in a number.")
->->-> wait {
->->->-> ClearScreen
->->->-> birth_year_function
->->-> }
->-> } else if (IsNumeric (result) = true) {
->->-> if (LengthOf (result) = 4) {
->->->-> game.pov.year_integer = ToInt (result)
->->-> } else if (not LengthOf (result) = 4) {
->->->-> ClearScreen
->->->-> msg ("Please type in 4 digits.")
->->->-> wait {
->->->->-> ClearScreen
->->->->-> birth_year_function
->->->-> }
->->-> }
->-> }
-> }
]]></function>

OurJud
26 Nov 2014, 19:14
Is 'result=' case sensitive?

TP seems to suggest not in her last post, by saying I should write the answer in lowercase just in case the player capitalises the name. But when I try the sequence and capitalise the name, it sees it as a wrong answer.

How would I allow for both in the 'result= ' field?

Oops, never mind. Just looked through TP code again and noticed the 'if LCase' exception.

jaynabonne
26 Nov 2014, 20:15
Well, I wasn't going so much on traditions as much as I just felt a cringe seeing the "n" comparison in there - because it opens up a whole bunch of additional cases. What if they type "l"? What if they try to look at the Tom (x tom)? Stuff like that. If you intend it to look like a standard prompt, then it puts a larger burden on you to make it real.

Also, and I forgot to mention this earlier. when does this script happen? Is it as soon as you enter the room, or does the player kick it off with some command? If it's the former, then disregard the rest. If it's the latter, then you'd have to deal with the case of someone typing "n" outside the conversation anyway.

Probably just babbling on my part. I hope that didn't confuse things. :)

OurJud
26 Nov 2014, 20:20
jaynabonne wrote:Well, I wasn't going so much on traditions as much as I just felt a cringe seeing the "n" comparison in there - because it opens up a whole bunch of additional cases. What if they type "l"? What if they try to look at the Tom (x tom)? Stuff like that. If you intend it to look like a standard prompt, then it puts a larger burden on you to make it real.

Also, and I forgot to mention this earlier. when does this script happen? Is it as soon as you enter the room, or does the player kick it off with some command? If it's the former, then disregard the rest. If it's the latter, then you'd have to deal with the case of someone typing "n" outside the conversation anyway.

Probably just babbling on my part. I hope that didn't confuse things. :)


It's triggered on entering, Jay. However, I've stripped it right down and made it far more simplified.

Now, it's a simple, single question to gain access to the backroom. Any input other than the correct answer to his question gets you thrown back outside. Logic says you would lose your gun at this point, but I'm still trying to figure out how I'd do that, if indeed I decide to go that way.

jaynabonne
26 Nov 2014, 20:26
I suppose it depends on where you want it to go! You can move an object to any room simply by setting its parent (or by using the "move object" script command).

OurJud
26 Nov 2014, 20:38
jaynabonne wrote:I suppose it depends on where you want it to go! You can move an object to any room simply by setting its parent (or by using the "move object" script command).


Thanks. I'll try the move object command. The obvious room to move it to would be the backroom you were trying to gain access to, so that when you eventually get there, you can reclaim it.

jaynabonne
26 Nov 2014, 21:05
Ah, yes. That makes sense. :)

Silver
26 Nov 2014, 21:17
both of the games I'm writing fall under the dystopia umbrella.

if you're the only person suffering the nightmare then there's no NPCs to worry about. Well there is, but not in the complex human sense.

OurJud
26 Nov 2014, 21:21
Silver wrote:both of the games I'm writing fall under the dystopia umbrella.

if you're the only person suffering the nightmare then there's no NPCs to worry about. Well there is, but not in the complex human sense.

Mmm, care to elaborate? Are you saying you feel such a game doesn't require any NPC interaction?

Silver
27 Nov 2014, 00:41
i'm refering to my own approach presently...