OFPEC Forum
Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting General => Topic started by: Mr.Peanut on 24 Aug 2007, 20:11:05
-
This purpose of this thread is to gather a list of the most common scripting errors to help others. They might be simple. They might be subtle. I will sort it and make a list. Give a brief description, code and solution code. sqf script format preferred.
I'll start the list off:
1) Not initialising an array before adding values. You must set an array to at least empty [] before you can use +[ ]
Wrong: :no:
_y = _this;
_x = _x + [_y];
Right: :yes:
_y = _this;
_x = [];
_x = _x + [_y];_y = _this;
_x = [_y];
_x = _x + [_y];
2) Not initialising variable before a loop. A local variable that appears only inside a loop does not exist outside the loop. If you want to access the variable you must set it to something(anything) before the loop. This includes all braced looping constructs as forEach, while do, count and the conditional construct if then
Wrong: :no:
_x = _this;
while {"_i=0","_i=_i+1","_i<10"} do {
_y = _x + 1;
};
print format["%1",_y];_x = _this;
if (_x>5) then {_y=10;} else {_y=1};
};
print format["%1",_y];
Right: :yes:
_x = _this;
_y = 0;
while {"_i=0","_i=_i+1","_i<10"} do {
_y = _x + 1;
};
print format["%1",_y];_x = _this;
_y = 0;
if (_x>5) then {_y=10;} else {_y=1};
print format["%1",_y];
-
Great idea Mr. Peanut-- here is the start of a checklist of errors to avoid when making a cutscene:
Its been very helpful for me in constructing missions to think about all the things that can go wrong or that the human player can make wrong before a cutscene :scratch:
Cutscene Errors: :no:
Did you forget to remove the player's NV goggles?
Do you want the screen to look like aa TV set frame?
Are the characters in the cutscene still alive? Will they move out of the frame?
Is the time acceleration still at 4x or did you set it back to 1 for the cutscene?
Can game characters interrupt with radio commands?
Are the characters looking at each other?
Right :yes::
; Is the character even alive to have this cutscene conversation?
if (not alive _maria) then {exit}
;Create the camera
_camera = "camera" camcreate [0,0,0]
_camera cameraeffect ["internal","back"]
_camera camcommit 0
; Prevent characters from interrupting with radio
enableradio false
;Fix TV frame
cutobj ["tvset"," ",0]
;Fix NV goggles
_player action ["NVGOGGLESOFF",_player]
; Fix time acceleration problem
setAccTime 1
; Shot of Safehouse Cabin
_camera camPrepareTarget [30270.69,112198.96,-15456.32]
_camera camPreparePos [14657.35,14687.58,10.24]
_camera camPrepareFOV 0.700
_camera camCommitPrepared 0
@camCommitted _camera
; Are the characters looking at each other?
_maria lookat _player
_player lookat _maria
;Will the characters run away mid-scene?
_player setbehaviour "Safe"
_maria setbehaviour "Safe"
~10
; End the scene
_camera cameraeffect ["terminate","back"]
camdestroy _camera
; Re-establish radio communications between characters
enableradio true
exit
-
Cool.... :cool2:
OnMapSingleClick
Wrong :no:
OnMapSingleClick [];
Right :yes:
OnMapSingleClick "";
In a trigger's On Activation Field
Wrong :no:
onMapSingleClick "this={_pos} execVM "myScript.sqf";
onMapSingleClick "this="_pos" execVM (myScript.sqf);
Right :yes:
onMapSingleClick "this=[_pos] execVM ""myScript.sqf""";
Using OnMapSingleClick in a script itself, one of the biggest errors is not disabling map click so further map clicks don't change the variable _pos.
Wrong :no:
_pos = _this select 0;
hMove setPos [(_pos select 0),(_pos select 1),0];
heliPilot doMove _pos;
Right :yes:
_pos = _this select 0;
// disable further map clicks
OnMapSingleClick "";
hMove setPos [(_pos select 0),(_pos select 1),0];
heliPilot doMove _pos;
I'm no expert by far, and I had lots of trouble with this very useful command for awhile. Hope it helps somebody else. :)
-
this one is very helpful Nixer, i've made that "double effect" map click mistake ::)
-
For ArmA, you can no longer use curly braces with onMapSingleClick you must use doubles quotes. The double quotes for the trigger fields above ar how they look in the mission.sqm not in the editor, right?
-
Nope... :no:
That's copied straight from the on Activation field of a trigger, in the editor. It took me literally days to figure that one out. I tried hundreds of combinations. :weeping:
You still use the curly braces to disable Map Clicks. As far as I know, that is the only place you do. doh.... :-[
Yep..... you are right Mr.Peanut. Sorry for the FUD.
// disable Map Single Clicks
[color=red]OnMapSingleClick[/color] "";
if embaressed [color=red]exitWith[/color] {};
-
One common problem I come across is displaying a debug message through hint or sidechat. The problem is if you run a function expecting a quick response, sometimes you won't see it. The reason could be because the display's for hint and sidechat aren't quite initialized yet and your trying to write to those displays. One way to test if this the problem is to sleep 2; just before the message. The same thing can happen if you create your own dialog display and then try to write to for instance a list box before the display is initialized.
-
Still a bit confused by the above posts, what is the final way to run a map click and then disable it after clicking?
-
Simply in a script
arrayName=[];
OnMapSingleClick "arrayName=_pos";
OnMapSingleClick "";
Hope that helps. :yes:
-
thanks!!!! :)