Home   Help Search Login Register  

Author Topic: Script syntax help  (Read 1865 times)

0 Members and 1 Guest are viewing this topic.

Offline samsamps

  • Members
  • *
Script syntax help
« on: 24 Sep 2008, 04:31:09 »
I'm not very experienced with programming or scripting in general. It's an extremely simple script but im not familiar with the syntax required to make this work. For reference, _x is the #number of enemy present. I want the script to clean up after itself when the enemy are taken care of.


if (_x > 0) then {goto loop}
if (_x = 0) then {0 objstatus DONE; obj0_done=true;deletemarker objeast;}

Offline hoz

  • OFPEC Site
  • Administrator
  • *****
Re: Script syntax help
« Reply #1 on: 24 Sep 2008, 04:54:20 »
Is this related to scripting in missions or addons?
Xbox Rocks

Offline samsamps

  • Members
  • *
Re: Script syntax help
« Reply #2 on: 24 Sep 2008, 05:32:32 »
It is part of a mission. The complete script is used in a mission to detect whether enemies are present in a specific area and sets objective 0 as done once that area is clear.

Offline hoz

  • OFPEC Site
  • Administrator
  • *****
Re: Script syntax help
« Reply #3 on: 24 Sep 2008, 06:04:31 »
Moved the topic so you get the right help...

You should post the whole script so we can see what we are dealing with.
Xbox Rocks

Offline Wolfrug

  • Addons Depot
  • Former Staff
  • ****
  • Official OFPEC Old Timer
Re: Script syntax help
« Reply #4 on: 24 Sep 2008, 10:46:48 »
Yes, more of the script might be usesful - as well as any possible error messages etc. that you get.

Two things in the snippet you've left:
1) Don't use _x as a variable, _x is a "magic variable" used in many commands such as forEach - it's much better to name them something appropriate like _enemyleft or so :) Prevents confusion!
2) To check if variable _x equals variable _y, use double =='s, so if (_x == 0) then {...}. A single = assigns a variable a value. So x = 0 means that x equals 0. x == 0 is a boolean check to see if x equals zero. And so on. :)

Wolfrug out.
"When 900 years YOU reach, look as good you will not!"

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Script syntax help
« Reply #5 on: 24 Sep 2008, 12:24:19 »
You can't have a goto inside { }. goto is specific to SQS syntax, whereas you can only have SQF statements inside { }.

If you wanted to do this in SQS, you need to use ?:
Code: (SQS) [Select]
#loop
; do stuff
~1
? x > 0 : goto "loop"

In SQF you might do something like this:
Code: (SQF) [Select]
while { x > 0 }
{
    // do stuff
    sleep 1;
};

0 objstatus DONE;
obj0_done=true;
deletemarker objeast;

Of course, I'm guessing a bit here, since you didn't give context for what you were doing.
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline samsamps

  • Members
  • *
Re: Script syntax help
« Reply #6 on: 25 Sep 2008, 19:06:37 »
Doesnt seem to be working for me. It is an .sqs file.
Code: [Select]
#Loop

trigeast = createTrigger ["EmptyDetector", position DetectLoRgt ]

trigeast setTriggerActivation ["EAST", "PRESENT", false]
trigeast setTriggerArea [500, 700, 0, true ]

trigeast setTriggerType "switch"

trigeast setTriggerStatements ["this", "", ""]

trigger setTriggerTimeout [0, 0, 0, false ]

~1

_vehListB = list trigeast

east_troops = []

{{if (alive _x) then {east_troops = east_troops + [_x]}} forEach crew _x} forEach _vehListB

~1


hint format ["East soldiers still alive:\nEast: %1",{alive _x} count east_troops]

~1

;Here the trigger you just created is deleted, so less lag!

deletevehicle trigeast

~1

if _x > "0" then goto "Loop" else 0 objstatus DONE; obj0_done=true;deletemarker objeast

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Script syntax help
« Reply #7 on: 25 Sep 2008, 19:33:00 »
By saying "You can't have a goto inside { }", I was implying that you couldn't use goto with if, which uses {}. I didn't mean just to remove the {}!

Code: (replacing last line of your script) [Select]
; if _x is too large, loop again.
? _x > 0 : goto "Loop";

; Didn't loop, so do this instead.
0 objstatus DONE;
obj0_done=true;
deletemarker objeast
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline samsamps

  • Members
  • *
Re: Script syntax help
« Reply #8 on: 25 Sep 2008, 19:42:27 »
Ah, ok. I tried this out but it seems that replacing the code with yours doesn't work. Its bypassing the part where its supposed to goto loop. I think _x isnt the correct variable im supposed to use maybe? I'm not sure exactly what else i can use to compare it to.
« Last Edit: 27 Sep 2008, 09:18:28 by samsamps »

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re: Script syntax help
« Reply #9 on: 27 Sep 2008, 12:26:42 »
Do remember that marker names should be enclosed in quotes, for example:

deletemarker objeast  >>>>  deletemarker "objeast"

If I read it wrong, forgive me.    :cool2:


Planck
I know a little about a lot, and a lot about a little.

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Script syntax help
« Reply #10 on: 27 Sep 2008, 19:00:19 »
Sorry, yes, I was just copying what I was given (and yes, it is possible you might put the name of a marker inside a variable and then you'd not need the quotes, but yes, it was probably not the case here).
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)