Requiring certain things to be done before a door is usable

savestheday510
10 Oct 2015, 04:38
Hey all. Just discovered this wonderful program and I'm currently creating my first game. I understand how to unlock a door but I'd like to know if there's a way to require you to do a number of things before a door is usable. For example I want the player to have to talk to a number of NPCs before they can move on to a new room.

Apologies if this is a common question but I looked around a bit and didn't see anything like this on the front page.

HegemonKhan
10 Oct 2015, 11:29
this is a bit complicated and possibly advanced for a new person, but if you're interested, for an example:

(this isn't the best design... I'm still a code noob, especially with dialogue designs. The good programmers here, can help you with crafting a much better dialogue design~system than mine below)

-----------

'door' Object's 'unlock~open' Verb~s:

// checking conditions (Objects' Attributes compared~constrasted to a Value or another Objects' Attributes) is done via the 'if' Script:

add new script -> scripts -> 'if' Script -> (see below)

if [EXPRESSION] ((npc_1.dialogue_state > 0) and (npc_2.dialogue_state > 0) and (npc_3.dialogue_state > 0))

-> then: -> add new script -> (whatever the scripts to 'unlock~open' the 'door' Object)

else if [EXPRESSION] ((npc_1.dialogue_state > 0) and (npc_2.dialogue_state > 0))

-> then: -> add new script -> output -> 'print a message' Script -> (see below)

print [EXPRESSION] "You need to go talk to " + npc_3.alias + ", before the door will unlock~open."

else if [EXPRESSION] (npc_1.dialogue_state > 0)

-> then: -> add new script -> output -> 'print a message' Script -> (see below)

print [EXPRESSION] "You need to go talk to " + npc_2.alias + " and " + npc_3.alias + ", before the door will unlock~open."

else -> add new script -> output -> 'print a message' Script -> (see below)

print [EXPRESSION] "You need to go talk to " + npc_1.alias + ", " + npc_2.alias + ", and " + npc_3.alias + ", before the door will unlock~open."

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

creating~adding the 'npc' Objects: (I presume you know how to create~add Objects, and how to have them where you want them)

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

creating~adding the 'dialogue_state' Int (Integer) Attributes to the 'npc' Objects (for each of them):

'npc_1 or npc_2 or npc_3' Object -> 'Attributes' Tab -> Attributes -> Add -> (see below, repeat as needed)

(Object Name: npc_1 or npc_2 or npc_3)
Attribute Name: dialogue_state
Attribute Type: int (Integer: non-decimal numbers)
Attribute Value: 0

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

conceptually why we're doing this (this goes beyond just the requirements for unlocking~opening the door):

npc_1.dialogue_state = 0 ---> you've not yet talked to npc_1 at all
// you talk to npc_1, which changes the dialogue state to 1, via: add new script -> variables -> 'set a variable or an attribute' Script -> (see below)
// set variable npc_1.dialogue_state = [expression] 1
npc_1.dialogue_state = 1 ---> you've talked to npc_1, but you won't advance to dialogue state 2 until you talked to npc_2 about x topic first

npc_2.dialogue_state = 0 ---> you've not yet talked to npc_2 at all
// you talk to npc_2, which changes the dialogue state to 1, via: add new script -> variables -> 'set a variable or an attribute' Script -> (see below)
// set variable npc_2.dialogue_state = [expression] 1
npc_2.dialogue_state = 1 ---> you've talked to npc_2, but you won't advance to dialogue state 2 until you talked to npc_1: (see below)
// in code (for brevity): if (npc_1.dialogue_state > 0) { npc_2.dialogue_state = 2 }
// since, you already talked to npc_1, upon talking to npc_2 again, you advance to dialogue state 2 with npc_2

etc etc etc... I hope you get the structure+concept now...

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

too tired~lazy, so quickly:

as implied~said~seen~shown from the above... in your 'talk' Verbs with the 'npc' Objects, you're going to use a similar 'if' Scripting structure as you did for the 'door' Object's 'unlock~open' Verb.

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

P.S.

boolean (true~false) logic truth tables:

condition 1 logic_operator condition 2 ====> return value~state

AND (and):

https://en.wikipedia.org/wiki/Truth_table

true and true ====> TRUE
true and false ====> FALSE
false and true ====> FALSE
false and false ====> FALSE

OR (or):

https://en.wikipedia.org/wiki/Truth_table

true or true ====> TRUE
true or false ====> TRUE
false or true ====> TRUE
false or false ====> FALSE

NOT~NEGATION (form1: x <> x, or form2: not x = x):

not true ====> FALSE

not false =====> TRUE

https://en.wikipedia.org/wiki/De_Morgan%27s_laws

not (A and B) ====> (not A) or (not B)
not (A or B) ====> (not A) and (not B)

--------

(not sure if quest has XOR)

XOR (eXclusive OR):

https://en.wikipedia.org/wiki/Exclusive_or

true or true ====> FALSE
true or false ====> TRUE
false or true ====> TRUE
false or false ====> FALSE

The Pixie
10 Oct 2015, 15:16
savestheday510 wrote:Hey all. Just discovered this wonderful program and I'm currently creating my first game. I understand how to unlock a door but I'd like to know if there's a way to require you to do a number of things before a door is usable. For example I want the player to have to talk to a number of NPCs before they can move on to a new room.

Apologies if this is a common question but I looked around a bit and didn't see anything like this on the front page.

It is the sort of thing that you would think would be very common, but I do not remember it being asked recently.

The general approach is to have a flag on each NPC, and to turn the flag on after the conversation. Exactly how you do that depends on how conversations are set up, but you need a script to run, and to include the "Set object flag" script. Set the object to the NPC, and the flag name to, for instance, "hadconversation".

For your exit, tick the "Run a script..." checkbox. Select the "If..." script, and in the expression box you need to check each NPC has had the conversation. If might look like this, if the NPCs are mary, frankie and dave (you need to get their names exactly right, including capitals).
mary.hadconversation and frankie.hadconversation and dave.hadconversation


Then you need to add a script to the "Then" part. Select "Move object", set the first object to the player and the second to the room to go to.

Now click on "Add else", and add a "Print a message". Type in something appropriate.

It should look like this:
conditional_exit.png

savestheday510
10 Oct 2015, 17:09
Awesome guys. Thanks!

savestheday510
11 Oct 2015, 20:02
The Pixie wrote:

"savestheday510"

Hey all. Just discovered this wonderful program and I'm currently creating my first game. I understand how to unlock a door but I'd like to know if there's a way to require you to do a number of things before a door is usable. For example I want the player to have to talk to a number of NPCs before they can move on to a new room.

Apologies if this is a common question but I looked around a bit and didn't see anything like this on the front page.


It is the sort of thing that you would think would be very common, but I do not remember it being asked recently.

The general approach is to have a flag on each NPC, and to turn the flag on after the conversation. Exactly how you do that depends on how conversations are set up, but you need a script to run, and to include the "Set object flag" script. Set the object to the NPC, and the flag name to, for instance, "hadconversation".

For your exit, tick the "Run a script..." checkbox. Select the "If..." script, and in the expression box you need to check each NPC has had the conversation. If might look like this, if the NPCs are mary, frankie and dave (you need to get their names exactly right, including capitals).
mary.hadconversation and frankie.hadconversation and dave.hadconversation


Then you need to add a script to the "Then" part. Select "Move object", set the first object to the player and the second to the room to go to.

Now click on "Add else", and add a "Print a message". Type in something appropriate.

It should look like this:
conditional_exit.png



One small question. I'm not seeing 'player' as an option to set the object to for the if -- move object?

The Pixie
11 Oct 2015, 20:12
You should have a line that starts "Move object", with four dropdowns, and the word "to" between the second and third. The first and third should be set to "object". You should then see "player" in the lists for the second and fourth (though you only want it for the second).

If you do not see it, just check whether it is in the list of things on the left. i guess it is possible you deleted it somehow.

Try clicking on code view (under the script if online, seventh icon above the script if offline). The line in question should look like this:
MoveObject (player, room)

If you can find MoveObject , you could type in "player".

If you are editing offline, you could upload your game for someone to look at.

savestheday510
11 Oct 2015, 22:56
The Pixie wrote:You should have a line that starts "Move object", with four dropdowns, and the word "to" between the second and third. The first and third should be set to "object". You should then see "player" in the lists for the second and fourth (though you only want it for the second).

If you do not see it, just check whether it is in the list of things on the left. i guess it is possible you deleted it somehow.

Try clicking on code view (under the script if online, seventh icon above the script if offline). The line in question should look like this:
MoveObject (player, room)

If you can find MoveObject , you could type in "player".

If you are editing offline, you could upload your game for someone to look at.


Thanks so much for your help. I have the flags set up for the door requirement and can get through it after speaking with the NPCs. The only problem now is what it does if you haven't spoken with the NPCs first.

Here is how I set it up:


But when I test it without having spoken to those NPCs I get this:

The Pixie
12 Oct 2015, 06:56
Sorry, my bad. Try this as the expression at the top:
GetBoolean(Jiyeon, "hadconversation") and GetBoolean(Qri, "hadconversation") and GetBoolean(Hyomin, "hadconversation")

savestheday510
12 Oct 2015, 15:02
The Pixie wrote:Sorry, my bad. Try this as the expression at the top:
GetBoolean(Jiyeon, "hadconversation") and GetBoolean(Qri, "hadconversation") and GetBoolean(Hyomin, "hadconversation")


That did it! Thanks so much for your help!