Home   Help Search Login Register  

Author Topic: Declaring Local\Global Variables...!??!  (Read 2836 times)

0 Members and 1 Guest are viewing this topic.

zsa_zsa_rasputin

  • Guest
Declaring Local\Global Variables...!??!
« on: 20 Aug 2002, 13:40:03 »
I have noticed that variables sometimes have to be declared in a script, but not always...!?

ie. In a camera script you can simply put:
(Please forgive any syntax errors as I normally just cut n paste(!))

Cam CamSetTarget BoringMan
Cam CamSetRelPos (2, 5, 20)
etc etc etc

where as in a DIFFERENT EXTERNAL script, you have to DECLARE "BoringMan" thus:

_this _BoringMan = select 0

Or something, then for the rest of the script you have to add an underscore (_) before the units name for the whole time, for example:

RemoveAllWeapons _BoringMan

WHAT I WANT TO KNOW IS:
Is there any tutorial or document to be found on the site to explain variable usage and the language used in the game or if not, can someone do a simple, basic tutorial...???

Does ANYONE actually understand what I've been talking about throughout this whole thread!??!  :-[

Dan  ;D
« Last Edit: 20 Aug 2002, 13:41:06 by zsa_zsa_rasputin »

Bremmer

  • Guest
Re:Declaring Local\Global Variables...!??!
« Reply #1 on: 20 Aug 2002, 14:52:07 »
Hello Dan

I think I understand your question - You want to know the difference between global and local variables, and why they are used the way they are.

Here's my take on the subject ->

First off using a command with a variable that has not been defined will do nothing. All variables must be declared somewhere. Exactly where will depend on if the variable is local or global.

Global variables can be declared anywhere - in an objects indenty field, triggers, waypoints, scripts, really just about anywhere. Once declared the variable can be used (and modified) throughout the game using triggers, scripts, you name it. The point is that global variables are accessable to the whole game engine.

Local variables can only be defined within a script, and they are only used in that particular script. If you define a local variable in a script then that local variable in NOT accessable outside the script. eg if you define _unit = player in a script then the condition getdammage _unit > 0.5 will NOT work in a trigger. (As you noted local variables must be preceeded by an underscore, eg _unit).

So why use local variables rather than global ones? Consider if you want to run the same script for several different units. You could write a several script, identical apart from the global variables that reference the units you want the scripts to work for. Alternatively you can transfer the global variable to a local one allowing you to use a single script. eg:

[bob] exec "script.sqs"
[jim] exec "script.sqs"
[ian] exec "script.sqs"

******************
;script.sqs
_unit = _this select 0

******************

For each seperate run of the script _unit will have a different value (bob, jim or ian).

Hopefully all the above made some sort of sense.

Cheers

Offline KTottE

  • Former Staff
  • ****
Re:Declaring Local\Global Variables...!??!
« Reply #2 on: 20 Aug 2002, 18:03:00 »
Well, to clear a few things up.

Cam ="Camera" CamCreate[0,0,0]

Creates a camera, we all know that. Cameras are treated as units by the game, sort of, so Cam in this case is the name of the camera/unit.
You could put: _Cam, Camera01, BigPileOfRubbish or something completely different, just as you can name your units to whatever you want. Although I recommend following certain naming conventions:

Name them for what they are, and use the same kind of names for the same kind of units, only add numbers at the end.
Cameras will be called: Cam/Camera01, 02, 03 and so on
Infantry: InfUnit01, 02, 03
Armor: ArmUnit01, 02, 03
Aircraft: AirUnit01, 02, 03
(Special units, main characters in the plot, the player and so on should be named with the prefix for what they are: Inf, and the name of the unit. InfBob, InfRonaldMcDonald and so on)

Keep it short.
Longer than 8 letters will be difficult to remember, and to type out.

Anyway, now that you all know that =)

Let's take an example, I always name my cameras _camera01, 02, 03 and so on, because this is how they are named in clipboard.txt when using the "camera.sqs" feature.
Always name them 01, 02, 03 and so on, and keep track of how many cameras you have, since you have to terminate them at the end of a mission. Otherwise the mission will not end.

And about variables in general, you don't have to make a variable local by putting in that _.
Although, you do not make them global by just putting
JimBob = this select 0
Can't remember the exact command for global variables, but just check the ComRef and find out.

PS. If you haven't looked it up in the next hour or so, I will come back and post the exact command.


"Life is not a journey to the grave with the intention of arriving safely in a pretty and well preserved body, but rather to skid in broadside, thoroughly used up, totally worn out, and loudly proclaiming 'WOW What a Ride!'"

T.S.C.Plage

  • Guest
Re:Declaring Local\Global Variables...!??!
« Reply #3 on: 20 Aug 2002, 20:21:29 »
Hey KTottE,

can you give me an explaination of that "camera.sqs" feature, please?

I've played around with it but if I press CTRL no clipboard.txt is generated and saved somewhere.

Thanks
Plage

Offline KTottE

  • Former Staff
  • ****
Re:Declaring Local\Global Variables...!??!
« Reply #4 on: 20 Aug 2002, 20:36:24 »
Of course I can explain, since the Editors Depot isn't up yet (Well, nothing on MkII is up yet) which is where this info should be found later on.

I will explain it all, not just the clipboard.txt part, since more people may see this and take advantage of it.

---------------Return of "Camera.sqs"----------------

Have you ever wondered how you should get those pesky x,y,z coordinates for your cutscenes?
Well, here we go then.

In your player's init field, put:
this exec"camera.sqs"
You don't have to create a script, no camera.sqs file needs to be in your mission folder, just type that and press "preview".

Now, you are in a Gods-Eye-View mode where you can zip around the island in your brand new camera(?).
The controls are:

Forward - (as defined by you in the options) / Up Arrow
Backward - (as defined by you in the options) / Down Arrow
Left - (as defined by you in the options) / Left Arrow
Right - (as defined by you in the options) / Right Arrow

Up - (as defined by you in the options) / Page Up
Down - (as defined by you in the options) /Page Down

Turn Left - Keypad 4
Turn Right - Keypad 6
Tilt Up - Keypad 8
Tilt Down - Keypad 2

That's all the controls I can think of right now.

Anyway, just move your camera to a place where you want it to be in your cutscene/intro, and when you are happy, press your left "CTRL" button.
Now, alt-tab out of OFP, and go to your ofp main folder.
Default:
C:\Operationflashpoint\

In there, should be a file called clipboard.txt
Open that up and you will see this:

;=== 19:30:19
_camera camSetTarget [102832.63,-27627.95,-18070.41]
_camera camSetPos [9666.20,3874.45,1.39]
_camera camSetFOV 0.700
_camera camCommit 0
@camCommitted _camera

(With different info of course)

CamSetTarget = The exact location your camera is looking at.
CamSetPos = The exact position of your camera.
CamSetFOV = The Field Of View of your camera, (0.700 = normal)

Anyway, that should be all for now. Once the editors depot is up and running this info will be found there, and people asking for it will be chewed out by us =)
"Life is not a journey to the grave with the intention of arriving safely in a pretty and well preserved body, but rather to skid in broadside, thoroughly used up, totally worn out, and loudly proclaiming 'WOW What a Ride!'"

Offline Dinger

  • Contributing Member
  • **
  • where's the ultra-theoretical mega-scripting forum
Re:Declaring Local\Global Variables...!??!
« Reply #5 on: 21 Aug 2002, 12:26:56 »
That is cool (clipboarding).
Other ways to return the X,Y,Z pos:
use my LD as editing tool script (better yet download the artillery one and use that, since it bypassing the "initialization" routine.  Point the Laser Designator at the target and copy the coordinates from the display.

Use that cool 1.75 editing console (don't know its name, or the author's, but it's stickied over at flashpoint1985.com), go to your position (camera position even) and type "getpos player" or whatever


Back to the issue of variables: I had similar problems not finding a tutorial like that.  So when someone asked about arrays, I wrote a draft of a tutorial on arrays and variables.  It didn't generate much enthusiasm, but it was in the old forum ina  thread entitled "question about arrays"

when I get home in a couple weeks, I can send it to you.
Dinger/Cfit