Home   Help Search Login Register  

Author Topic: brain trouble - if/then syntax  (Read 474 times)

0 Members and 1 Guest are viewing this topic.

Rokket

  • Guest
brain trouble - if/then syntax
« on: 02 Sep 2004, 13:03:54 »
I've modified a script from Johan Gustafsson's tutorial, and it works, but it has side-effects. My logic for the fix seems OK, but I can't figure the proper syntax. I'm not much of a scripter.

NOGAS SCRIPT: The script sets fuel to 0 in whatever vehicle the player gets in. I use a trigger to set a variable, so that the player drives along for a short bit, hits the trigger, and bang the script executes. Works fine. But the player can then get into 2 other vehicles, and I don't want those to run out of fuel too (that would be too frustrating). Trouble is, once the script executes, any vehicle the player touches is instantly set to 0 fuel.

ORIG SCRIPT: (in 3 vehicle inits)
---------------------------------------
_Unit = aP
_Vehicle = _this select 1
; Main loop
#Update
; Check if the unit is in the vehicle
? _Unit in _Vehicle AND nofuel: goto "nogas" ["nofuel" is trigger variable]
~1
goto "Update"

#nogas
_Vehicle setfuel 0
exit
-------------------------------------------

My fix logic would be to put in a "tripped" switch, so that once the script fires for one vehicle, it won't fire again:
-------------------------------------------
; Check if the unit is in the vehicle
? _Unit in _Vehicle AND nofuel AND NOT tripped: goto "nogas"

~1
goto "Update"

#nogas
_Vehicle setfuel 0
tripped=true
exit
---------------------------------------------
But this isn't working. If the logic is good, how can I write it? If the logic is bad, any fix suggestions?

Thanx

Offline dmakatra

  • Members
  • *
  • Better known as Armsty
Re:brain trouble - if/then syntax
« Reply #1 on: 02 Sep 2004, 13:22:01 »
I have a bad experience of booleans in script. I prefer using numbers, like this:

_Unit = _this select 0
_Vehicle = _this select 1
_i = 0
#Update
? _Unit in _Vehicle AND (nofuel == 1) AND (_i == 0): goto "nogas"
~1
goto "Update"
#nogas
_Vehicle setfuel 0
_i=1
exit

:beat: *Gets Shot* :beat:

Rokket

  • Guest
Re:brain trouble - if/then syntax
« Reply #2 on: 02 Sep 2004, 13:45:03 »
Thanks, Armstrong. makes perfect sense whe someone smart explains it!

I've run into another problem - and it's my brain, really - it still isn't working, and I've discovered part of the problem:

the same script is called in each of the 3 vehicle init lines...so it doesn't matter if one vehicle trips it, the others will never "know"... I think I have to find a way to have the script call from the trigger and look at each of the 3 target vehicles togther. But I'm not sure how, unless I could change those local variables ("_vehicle) to global (no "_"?)... but I couldn't get script to work from trigger because of the check unit thing.

Thanks, tho!

Rokket

  • Guest
Re:brain trouble - if/then syntax
« Reply #3 on: 02 Sep 2004, 14:12:41 »
Amstrong..THANK YOU. I changed local "_i" to global, and now all is well! Yea! I also added a bit to shut down loop once triggered.

-----------------------------
;nogas modified by Rokket, from Johan Gustafsson's "blowup" example
; only works completely because of The Real Armstrong (thanks)

_Unit = _this select 0
_Vehicle = _this select 1
i=0

#Update
? _Unit in _Vehicle AND (nofuel == 1) AND (i == 0): goto "nogas"
? i==1: goto "done"
~1
goto "Update"

#nogas
_Vehicle setfuel 0
i=1
exit

#done
exit
-----------------

'Preciate it!