Home   Help Search Login Register  

Author Topic: Setting an AI in one of two points  (Read 1926 times)

0 Members and 1 Guest are viewing this topic.

Offline Ironman

  • Former Staff
  • ****
    • {GSF} Home Page
Setting an AI in one of two points
« on: 26 Mar 2008, 17:57:17 »
Will this move a soldier to the marker if _x = 0? Well, I know it won't because I get an error, so if someone can tell me the proper coding, I would appreciate it.

The error has something to do with the _mPos(x,y,z) and when i use setPos[_mPos]

+East soldier's name is e1
+x1 is a marker's name

_mPos = getMarkerPos "x1"
_x = floor random 2

if(_x = 0)
{
e1 setPos[_mPos]
}
TS3 IP: tor.zebgames.com:9992

Offline Wolfrug

  • Addons Depot
  • Former Staff
  • ****
  • Official OFPEC Old Timer
Re: Setting an AI in one of two points
« Reply #1 on: 26 Mar 2008, 18:13:50 »
Hey there! Might be a good idea to format your code into the proper code...bracket...format (using [ code ] [ / code ] )

Looks like you're using .sqf code, which means you will need to have ;'s at the end of each statement. Also, to check if two variables are equal to one another, you will need to use ==. Also, try to avoid using special local variables like _x in normal code, instead use something else, like, _nr. Also, for the if statement to work, you need to use then as well (if (stuff) then {code}). And finally : getMarkerPos "x1" will -already- give you an array in return, so you don't need to put the brackets around _mPos in the setpos. Also remember to run the .sqf code with execvm, or ArmA might get testy with you.  :good:

Code: [Select]
_mPos = getMarkerPos "x1";
_nr = floor random 2;

if(_nr == 0) then
{
e1 setPos _mPos
};

Hope I didn't miss anything!

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

Offline Ironman

  • Former Staff
  • ****
    • {GSF} Home Page
Re: Setting an AI in one of two points
« Reply #2 on: 26 Mar 2008, 19:22:42 »
Sorry, I am used to Java... don't need the Then lol
TS3 IP: tor.zebgames.com:9992

Offline Ironman

  • Former Staff
  • ****
    • {GSF} Home Page
Re: Setting an AI in one of two points
« Reply #3 on: 26 Mar 2008, 19:48:46 »
I am putting this in my Init.sqs file..... says it is missing a } but I don't know where.
TS3 IP: tor.zebgames.com:9992

Offline paritybit

  • Members
  • *
Re: Setting an AI in one of two points
« Reply #4 on: 26 Mar 2008, 22:09:58 »
Try posting the code that you added to the init file; if it isn't too long, just post the whole thing.  Also, as mentioned before, looks like you are using sqf format, you might want to change the name of the init file to init.sqf instead of init.sqs.  Use the # symbol in the buttons to enclose code with the correct tags so it displays as code.

Hard to help if we can't see your code.

Also, if I don't say it, somebody will come along and say it.  They don't like people to post two messages in a row, they'd rather that you modify the existing message to add the new content.
Heroes don't die -- they just respawn.

Offline Ironman

  • Former Staff
  • ****
    • {GSF} Home Page
Re: Setting an AI in one of two points
« Reply #5 on: 27 Mar 2008, 00:15:06 »

Init.sqs:

; ****************************************************************
; Script file for Armed Assault
; Created by: |ACS|Ironman
; ****************************************************************

;putting the enemy and hostages in one place or the other.

_mPos = getMarkerPos "x1";
_nr = floor random 2;

if(_nr == 0) then
{
   e1 setPos _mPos
};


; fade in from black over 6 seconds
titlecut ["|ACS| Hostage Rescue","BLACK IN",6]

; wait for 6 seconds for the fade to complete
~6

exit

sorry about that back to back posting, I did not know that is frowned upon
TS3 IP: tor.zebgames.com:9992

Offline paritybit

  • Members
  • *
Re: Setting an AI in one of two points
« Reply #6 on: 27 Mar 2008, 01:18:25 »
EDIT:  :-[ Please skip straight to Spooner's response (after this one) as I've got it all wrong.  Well, everything except the last paragraph where I suggest moving away from SQS.

Just like in Java, you need a semi-colon after every line.  (Well, actually, more semi-colons are necessary than in Java because of the need for them after some curly braces). 

You need to add a semicolon to this line:
Code: [Select]
e1 setPos _mPos;and possibly this line:
Code: [Select]
titlecut ["|ACS| Hostage Rescue","BLACK IN",6];and maybe this line:
Code: [Select]
~6;
And, honestly, if I were you I'd really think about changing it to SQF since you are familiar with Java.  The format will be much more familiar and I could help you better (as I never learned SQS, as I'm sure some other addon developers did not).  It would cut the confusion about what needs a semi-colon.  Also, you can use the // form of comment which is recognized the world over by software developers instead of the ; method which is not pretty (at least to me, a C#/Java/C++ guy).
« Last Edit: 27 Mar 2008, 02:07:51 by paritybit »
Heroes don't die -- they just respawn.

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Setting an AI in one of two points
« Reply #7 on: 27 Mar 2008, 01:22:31 »
Actually, paritybit, your statements are incorrect since this is an SQS file, not an SQF file.

However, even in SQF, which is what you are assuming the file is, you don't actually need a semi-colon after any line that is just before the end of a block (that is, immediately before a } ); the semi-colon in this case is entirely optional (although odd behaviour, this is the same convention as in ECMAScript/Javascript). Generally though, it is good style to always place a semi-colon at the end of every line, since then you don't have problems when you add another line after the "last" one in the block.

Everything in the file is SQS, but:
Code: (SQF) [Select]
if(_nr == 0) then
{
   e1 setPos _mPos
};
is SQF, which is a different syntax. Understandably, the interpreter is failing there, since it is only expecting SQS in this file. Either use SQS for that conditional expression:
Code: (SQS) [Select]
? _nr == 0 : e1 setPos _mPos
Or move to just using SQF in the file (when the file should be called init.sqf).

However, since you have professed a knowledge of Java, like paritybit, I'd really suggest you move to using SQF formatting exclusively since it is a lot closer to Java in syntax (SQS is closer to 1970s BASIC or assembly language: almost totally unstructured). SQS is only really supported by ArmA for backwards compatibility...

Please also consider using proper code formatting in your messages using the "code" BBCode tags (or just click the # button, just above the area you type your post in) as you've been requested to do twice already ;P
« Last Edit: 27 Mar 2008, 17:15:42 by Spooner »
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Ironman

  • Former Staff
  • ****
    • {GSF} Home Page
Re: Setting an AI in one of two points
« Reply #8 on: 27 Mar 2008, 06:58:38 »
O, ok, I thought someone was telling me to put the "[code /code]" crap in the init file. I am sorry, I am all sorts of confused today.

So, I should use sqf instead of sqs because it is easier since I have a knowledge of Java... is this correct?

SQF: need semi-colons
SQS: doesn't

??
« Last Edit: 27 Mar 2008, 07:05:16 by Ironman »
TS3 IP: tor.zebgames.com:9992

Offline paritybit

  • Members
  • *
Re: Setting an AI in one of two points
« Reply #9 on: 27 Mar 2008, 09:13:33 »
The difference is more extreme than that; but simply put: you will have an easier time with the sqf syntax if you're familiar with Java/C++/C# or any other programming languages with similar syntax.  The problem here seems to be that you are mixing the syntaxes (see Spooner's e-mail, which points out the problem).
Heroes don't die -- they just respawn.