Simple Dialogue tree

For questions about using Classic.

Post » Wed Nov 24, 2010 5:23 pm

Hi,


Currently i'am trying to script a simple dialogue tree. I know there is an example for dialogues using hash tables and text files but i want so write it down from scratch to understand the machanics.

Basically it should be simple, but i can't get it to work, maybe someone of you can give me a hint what i'am doing wrong.

Its starts with a simple message, the player can choose between two options (Yes/No). If the player klicks on the yes button i change a private variable of the button to 1(lets name it ChoiceA) and displays a second message, again with two options.

The "Yes" button is now set to ChoiceA=1. I include a condition to check if ChoiceA equals 1, and if this condition is true and the "Yes" button is clicked again, a third message should appear.

But my problem is, that if i click on the Button during the first message, the programm jumps automatically to the third message. So the second message never got displayed.

Anyone of you have a idea what i'am doing wrong?
B
2
G
2
Posts: 15
Reputation: 680

Post » Thu Nov 25, 2010 6:20 am

Hi. It's really difficult to pinpoint these types of problems without being able to see the events, but I'll throw a couple of ideas out...

It sounds as if the logic is flawed. Go through the events, thinking of them in sort of a flowchart way, and see if whatever state variables/conditions you're using actually keep the state from advancing to the next step until the proper user input is had. For instance, if you used a variable to temporarily signal a transition, then you'd usually need to set it back to zero/off upon that transition, so that it won't go to the next immediately.

Also, make sure that you are using a 'button clicked' condition, and not a 'button down' condition. That's a common mistake.

Not sure what else may cause your problem.
B
3
S
2
G
2
Posts: 187
Reputation: 1,449

Post » Thu Nov 25, 2010 12:29 pm

I would postes my events, but i can't post attachments in this forums. So i can't even post a screenshot.

But my events are really simple, there are only 3 of them:



1: On clicked Button: [list:2b49qy3n] a.Write Text
b. Button.Set"ChoiceA" to 0[/list:u:2b49qy3n]

2. On clicked Button:
Value "ChoiceA" equal to 0 [list:2b49qy3n]a.Write second Text
b.Button.Set"ChoiceA" to 1[/list:u:2b49qy3n]

3. On clicked Button:
Value"ChoiceA" equal to 1[list:2b49qy3n] a.Write third Text[/list:u:2b49qy3n]

Thats all. I tested if reseting the private variable to 0 does anything, like you suggested, but unfortunately there was no effect.

I see the problem. The programm executes all variable actions at one click. The message get displayed but only for a few milliseconds and then construct proceeds to the last one. The event chain does not wait for an input. It changes the variables on the first click on the button. I don't know why cause as you can see i told the program to change the value AFTER each click on the button.
B
2
G
2
Posts: 15
Reputation: 680

Post » Thu Nov 25, 2010 3:43 pm

When you click the mouse, the condition 'if mouse has been clicked' remains true for the whole event sheet until the next tick, not just for the first event that uses it. The simplest ways to fix it are to either order those events backwards or set a variable mouse clicked to 1 and check the variable in each event, like:

1: On clicked Button:
variable 'mouseclicked' = 0

a.Write Text
b. Button.Set"ChoiceA" to 0
c. set variable 'mouseclicked' to 1

2. On clicked Button:
variable 'mouseclicked' = 0
Value "ChoiceA" equal to 0

a.Write second Text
b.Button.Set"ChoiceA" to 1
c. set variable 'mouseclicked' to 1

3. On clicked Button:
variable 'mouseclicked' = 0
Value"ChoiceA" equal to 1

a.Write third Text
b. set variable 'mouseclicked' to 1

Then set the mouse clicked variable to 0 at the end of the event sheet.
Moderator
B
87
S
32
G
33
Posts: 3,005
Reputation: 27,397

Post » Thu Nov 25, 2010 3:45 pm

Hi. 'On a certain button clicked' type events will be true throughout the event sheet for the tick that it is true for that button, so all of those will execute in order.

Arranging them like so should work, assuming that 'ChoiceA' is zero by default:

[code:11fyr41t]On clicked Button:
Value "ChoiceA" equal to 0
a.Write Text
b. Button.Set"ChoiceA" to 1
Else
Value "ChoiceA" equal to 1
a.Write second Text
b.Button.Set"ChoiceA" to 2
Else
Value"ChoiceA" equal to 2
a.Write third Text[/code:11fyr41t]

Then you may need to reset 'ChoiceA' to zero or something that doesn't apply to those conditions, afterward, depending upon your needs.

All of the 'ChoiceA' tests are sub-events of the 'clicked button' event, and the Else conditions make sure that only one is true per tick.

Tulamide made a nice tutorial on that subject a while back: Introduction to branching.

That may help clear up the event logic for you.
B
3
S
2
G
2
Posts: 187
Reputation: 1,449

Post » Thu Nov 25, 2010 7:49 pm

Thanks for the help!

Both systems work and i'am sure i can use this knowledge in some advanced scripts.

I never thought that even branching that seems so easy and simple like this example can become complicated :)

I'am a bit ashamed of my self that i could not figure it out by my self. The "If - Else" script reminds me heavily on the old text rpg's i used to write in Qbasic ages ago :lol:
B
2
G
2
Posts: 15
Reputation: 680


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 1 guest