If carrying (object) AND (object) script?

OurJud
22 Dec 2015, 13:51
Is there a way to say this?

I have the trunk of a car which contains two objects, so I have to account for several outputs:

1. Both item there
2. One (or the other) of the items there
3. No items there

Now I know if I auto-list or use hyperlinks for my objects, Quest will handle all this for me, but I don't so am having to write a stack of if scripts. Only problem is, I don't know how to cater for neither item being in the trunk. I need an if player is carrying (object) AND (object) script, but don't know how to write it.

XanMag
22 Dec 2015, 14:16
If/then/if/then and your elses are messages like "you don't have the necessary objects to do that."

Nest an if inside other if.

OurJud
22 Dec 2015, 14:20
Pardon?

I'll try again.

There's a car. The trunk is open.
>search trunk

There's a rifle and flashlight here.
>take flashlight

Taken
>search trunk

There's a rifle here.
>take rifle

Taken
>search trunk

The trunk is empty.


How do I script that?

Father thyme
22 Dec 2015, 14:29
If you have the trunk as a container and examine trunk and it is empty then I believe the default message should come up.' It contains nothing at all.'

XanMag
22 Dec 2015, 14:30
Make the trunk a container?

Or make a trunk object and add the verb search. Then put an if/then/if/then script in there?

OurJud
22 Dec 2015, 14:44
Thanks, but I got there in the end. I remember I asked the same question last year for a different game, and managed to find the script from there.

For anyone interested, here's my roundabout, messed up, mental, unorthodox way of doing it:

if (Got(crowbar)) {
SetObjectFlagOn (player, "trunkopen")
if (Got(flashlight)) {
if (Got(rifle)) {
msg ("The trunk is empty.")
}
else {
msg ("A hunting rifle lies in the bed of the trunk.")
}
}
else {
if (Got(rifle)) {
msg ("A flashlight lies in the bed of the trunk.")
}
else {
msg ("A hunting rifle and flashlight lie in the bed of the trunk.")
}
}
}

ChrisRT
22 Dec 2015, 15:32
Looks like you beat me to it! I had a go at making an example scene using flags, expressions and a lot of ifs. Since I haven't tried posting code before, I'll try leaving it here anyway - hopefully this is how you do it?

<asl version="550">
<include ref="English.aslx" />
<include ref="Core.aslx" />
<game name="Multiple and-ifs">
<gameid>e7283b94-0d75-44fd-9748-ca50d405ebfe</gameid>
<version>1.0</version>
<firstpublished>2015</firstpublished>
<enablehyperlinks type="boolean">false</enablehyperlinks>
<autodescription />
<autodisplayverbs type="boolean">false</autodisplayverbs>
<attr name="autodescription_youarein_useprefix" type="boolean">false</attr>
<attr name="autodescription_youcansee" type="int">0</attr>
<attr name="autodescription_youcango" type="int">0</attr>
<attr name="autodescription_description" type="int">2</attr>
</game>
<object name="Forest Clearing">
<inherit name="editor_room" />
<description>You find yourself in a silent forest clearing, empty aside from an old blue car.</description>
<object name="player">
<inherit name="editor_object" />
<inherit name="editor_player" />
</object>
<object name="car">
<inherit name="editor_object" />
<look type="script">
if (not car trunk.isopen) {
msg ("An old, blue car with faded paintwork. The trunk appears to be closed, but unlocked.")
}
else {
msg ("An old, blue car with faded paintwork. The trunk is open.")
}
</look>
<scenery />
</object>
<object name="car trunk">
<inherit name="editor_object" />
<inherit name="container_open" />
<look type="script">
if (not car trunk.isopen) {
msg ("The trunk of the car is closed. It appears to be unlocked, however.")
}
else if ((GetBoolean(car trunk, "hasrifle")) and (GetBoolean(car trunk, "hasflashlight"))) {
msg ("The car trunk contains a flashlight and a rifle.")
}
else if ((GetBoolean(car trunk, "hasrifle")) and (not GetBoolean(car trunk, "hasflashlight"))) {
msg ("The car trunk contains a rifle.")
}
else if ((not GetBoolean(car trunk, "hasrifle")) and (GetBoolean(car trunk, "hasflashlight"))) {
msg ("The car trunk contains a flashlight.")
}
else {
msg ("Having taken the flashlight and rifle, the trunk is now empty.")
}
</look>
<feature_container />
<onopen type="script">
msg ("After some effort, the trunk of the car creaks open.")
</onopen>
<onclose type="script">
msg ("You close the car trunk - the slamming sound echoes through the otherwise quiet woods.")
</onclose>
<hidechildren />
<scenery />
<hasrifle />
<hasflashlight />
<isopen type="boolean">false</isopen>
<object name="flashlight">
<inherit name="editor_object" />
<take />
<takemsg>You take the flashlight.</takemsg>
<scenery />
<ontake type="script">
SetObjectFlagOff (car trunk, "hasflashlight")
</ontake>
<look>The flashlight appears old and worn, but is still functional.</look>
</object>
<object name="rifle">
<inherit name="editor_object" />
<take />
<takemsg>You take the rifle. It feels reassuringly heavy.</takemsg>
<scenery />
<ontake type="script">
SetObjectFlagOff (car trunk, "hasrifle")
</ontake>
<look>What appears to be a long-barrelled hunting rifle. It is covered with a layer of dust, but appears to be in working condition.</look>
</object>
</object>
</object>
</asl>

OurJud
22 Dec 2015, 15:37
So you can use 'and' to check for multiple objects?

ChrisRT
22 Dec 2015, 15:47
From my quick test, I managed to use 'and' in an expression to check for multiple flags, yes (I set up the flags beforehand under Attributes). I used the flags because an expression that checked for the actual objects themselves just came up with errors... I'm not sure exactly why.

Here's what it looks like in the GUI editor.

and-ifs.jpg

The Pixie
22 Dec 2015, 15:50
OurJud wrote:Thanks, but I got there in the end. I remember I asked the same question last year for a different game, and managed to find the script from there.

For anyone interested, here's my roundabout, messed up, mental, unorthodox way of doing it:

if (Got(crowbar)) {
SetObjectFlagOn (player, "trunkopen")
if (Got(flashlight)) {
if (Got(rifle)) {
msg ("The trunk is empty.")
}
else {
msg ("A hunting rifle lies in the bed of the trunk.")
}
}
else {
if (Got(rifle)) {
msg ("A flashlight lies in the bed of the trunk.")
}
else {
msg ("A hunting rifle and flashlight lie in the bed of the trunk.")
}
}
}

The basic structure is right, but it would be better to check if the item is in the trubk, not if the player does not have yet. You are assuming the player will not drop the rifle or flashlight. If he does, the game will report that they are in the trunk (whereever they are).
if (Got(crowbar)) {
SetObjectFlagOn (player, "trunkopen")
if (not flashlight.parent = trunk) {
if (not rifle.parent = trunk) {
msg ("The trunk is empty.")
}
else {
msg ("A hunting rifle lies in the bed of the trunk.")
}
}
else {
if (not rifle.parent = trunk) {
msg ("A flashlight lies in the bed of the trunk.")
}
else {
msg ("A hunting rifle and flashlight lie in the bed of the trunk.")
}
}
}

OurJud
22 Dec 2015, 16:41
Thanks, Chris. I was hoping 'and' could just be used with an if script. I don't want further complications by having to add flags all over the place. Good to know it can be done if needed, though.

TP, that's great, as when I started to wonder about the player dropping objects, my head almost exploded.

So, let me just check I understand. As it stands, the parent of those objects is simply the room. Are you saying drag and drop the objects to the 'trunk' object, so that trunk is their parent, and then use your script?

The Pixie
22 Dec 2015, 17:05
The parent is where it is, yes, so drag the items to the trunk in the editor, and that is where they start the game. If the player is holding them, then their parent is the player.

OurJud
22 Dec 2015, 17:35
Thanks.


OurJud
22 Dec 2015, 17:40
HegemonKhan wrote:
// these all do the same thing:

if (Got (hat) and Got (mat)) { /* scripts */ }


Sooooooo, 'and' can be used with regular if scripts, without having to resort to flags??

if Got objectA (give location description minus objectA)
if Got objectB (give location description minus objectB)
if Got objectA and objectB (give location description minus both objects)
else (give location description including both objects)

Makes far more sense than the complicated stack of ifs I had to use.

HegemonKhan
22 Dec 2015, 17:54
yep, and not just 'if' Scripts, but any Script that has an 'expression' section

the main thing that people mess up on, is that you need the full statement for each condition:

if (Got (hat and mat)) ----> ERROR
if (Got (hat) and (mat)) -----> ERROR

full statements (in this case, the statements are function calls) of the two conditions:

1. Got (hat)
2. Got (mat)

if (Got (hat) and Got (mat)) ----> NO error

full statements (in this case, the statements are Boolean Attribute flags) of the two conditions:

1. orc.dead
2. orc.equipped

if (orc.dead and orc.equipped)

full statements (in this case, the statements are Integer Attribute flags) of the two conditions:

1. player.strength > 50
2. player.endurance > 50

if (player.strength > 50 and player.endurance > 50)

full statements (in this case, the statements are String Attribute flags) of the two conditions:

1. player.status_effect = "poisoned"
2. player.magical_effect = "regenation"

if (player.status_effect = "poisoned" and player.magical_effect = "regeneration")

OurJud
22 Dec 2015, 18:40
HegemonKhan wrote:
if (Got (hat) and Got (mat))

I'm correct in thinking that this can't be done with the UI, and has to be typed in manually?

The Pixie
22 Dec 2015, 18:57
In the GUI, select "If", then set it to [expression], and then you have to type in this:
Got (hat) and Got (mat)

So yes, you can do it in the GUI, but I think at this point it is actually easier in code.

OurJud
22 Dec 2015, 19:04
Ah, okay. Thanks.

XanMag
22 Dec 2015, 20:38
By the way, perfect timing for this question! This will help tremendously as I add commands and verbs to X2. =)

OurJud
22 Dec 2015, 20:50
XanMag wrote:By the way, perfect timing for this question! This will help tremendously as I add commands and verbs to X2. =)

Glad I could help :mrgreen: