PDA

View Full Version : (if), (and), and (or) statements



Echo Ranger 449
January 2nd, 2008, 01:04 PM
I'm currently trying to make a "bonus scene" in the silent cartographer.

The title of it will be "Ambushed"

Summary of events
------
After the player has unlocked the security door and is now walking inside the outside entrance to the silent cartographer, an sword elite will fly down.

If the player tries to avoid the elite, he will find that there is a door that's locked (I made the necessary scenery to make adjustments for the difference in the door frame's size).

If the player kills the elite whilst still flying, then the door will unlock.
If the player causes the elite to engage him and enter the custom-made trigger at the front entrance, the elite will get out, execute a command list, then proceed to attempt to kill the player. When the player kills the him, the doors will unlock.
-----------------------

Notes:
doors that open when you approach are (I believe) called "small door", doors that open and close after being told to in the script are called "small door platform".

Now I could just use the small door platform, but before the player enters that part of the mission, I want the door to open and close as normal.

So here is what I did-
I used the small door before and after the scene. the "ambushed" door is the small door platform. When the ambushed mission begins, the old door is destroyed and the ambushed door is created. After the mission ends, the same thing happens.

My main issue is that I cannot make the "if banshee is killed or (banshee pilot gets out and gets killed), then unlock door" work.

I need to create an "if this then that" condition that will loop the "if ai_living_count equals 0" until it is met.

My problem was that I told the scenario "if commander gets out and is killed by player, then open door"- this means however, that if the player kills the elite before he gets out and executes the command list, the door won't open.

trigger: trigger1
encounter: angrycmder/commander
vehicle: shee1
command list: cmd1
door 1: before
door during the ambush scene: ambush door
door 3: after

(object_destroy before)
(object_create ambush_door)
(object_create shee1 )
(ai_place angrycmder/commander )
(sleep_until (volume_test_object trigger1 shee1 ))
(ai_exit_vehicle angrycmder/commander )
(ai_command_list angrycmder/commander cmd1 )
(sleep until (= 0 (ai_living_count angrycmder/commander)))
(object_destroy ambush_door )
(object_create after )


Now, if I put (sleep until (= 0 (ai_living_count angrycmder/commander)))
between "ai_place" and "sleep_until volume..." would that help?

I think if I did that, the sleep_until script would keep the others from running until the commander dies.

This is why I think the "if" statement would be better than "sleep until". However, for some reason I keep setting it up wrong because when I compile the script, sapien tells me "I expected a boolean function, but got a "void" value instead for "object_destroy ambush_door".

CtrlAltDestroy
January 2nd, 2008, 01:43 PM
(if <boolean> <then> <else, optional>)

(or <boolean> <boolean> <boolean> etc)

(and <boolean> <boolean> <boolean> etc)

you can nest them too


(if
(or
(and <boolean> <boolean>)
<boolean>
)
<then>
<else>
)

Also, the reason you are getting that error is because the command (object_destroy) does not return any information, let alone a boolean. All it does is destroy an object. For an if statement to work, it must consist of a condition.



EDIT: Sorry, only skimmed your post; reread it. Seems you already know all this... care to post the script you used with the if statement in place of the sleep_until command?

Echo Ranger 449
January 2nd, 2008, 06:39 PM
I believe I told it:

(if (= 0 (ai_living_count angrycmdr/commander)) (and (object_destroy ambush_door)(object_create after)))



by the way, does the <else> mean that it's a second event that will happen along with the <then> or is it an event that will happen if the statement is false?

Also, is the <else> required?

Finally, does putting
(sleep -1)
mean "ignore for now", a.k.a. "void"?

Patrickssj6
January 2nd, 2008, 06:45 PM
If True then "then"
If Not True then "else"

Else, in programming languages at least, is optional.

CtrlAltDestroy
January 2nd, 2008, 07:52 PM
I believe I told it:

(if (= 0 (ai_living_count angrycmdr/commander)) (and (object_destroy ambush_door)(object_create after)))



by the way, does the <else> mean that it's a second event that will happen along with the <then> or is it an event that will happen if the statement is false?

Also, is the <else> required?

Finally, does putting
(sleep -1)
mean "ignore for now", a.k.a. "void"?

Oh, I see, youre trying to use "and" to execute two commands at once, which is not its intended purpose.

Try:


(if (= 0 (ai_living_count angrycmdr/commander))
(begin
(object_destroy ambush_door)
(object_create after)
)
)

(sleep -1) means "sleep forever".

Echo Ranger 449
January 2nd, 2008, 08:11 PM
Alright, I got that statement (the "if he gets killed before exiting" statement)

(if
(= 0 (ai_living_count angry_commander/more_for_the_slaughter))
(begin
(object_destroy ambush_door)
(object_create after1)
)
)Now I just did the other if statement ( "if he exits the vehicle")


(if (volume_test_objects angry_elite commander_shee ) (begin
(ai_exit_vehicle angry_commander/more_for_the_slaughter)
(ai_magically_see_players angry_commander )
(ai_follow_target_players angry_commander/more_for_the_slaughter )
(sleep_until (volume_test_objects shaftA_entrance (players )))
(ai_command_list angry_commander/more_for_the_slaughter angry_fight )
(sleep_until (= 0 (ai_living_count angry_commander )))
(object_destroy ambush_door )
(object_create after1 )
)
)The script compiled successfully.

I will test it out and share the results ASAP.


>>>Neither of them worked.
The Elite did not exit the vehicle when he entered the trigger and the doors did not unlock when I killed him in the shee.

This was placed inside a mission script, which is initially dormant.
If I made these two if statements a script on their own, say,

(script continuous killed_before_exit
<all that script here>)

and

(script continuous killed_after_exit
<all that script here>)

then place a
(wake killed_before_exit )
(wake killed_after_exit )
inside the mission script, would that work?



Trigger was actually angry_elite
AI was actually angry_commander/more_for_the_slaughter
etc., etc... I'll explain later.


>>>It works! script continuous works!
Well...sort of.
The first door that spawns does not get deleted...even though it should. Script functionality is beginning to remind me of modding halo pc.