Home   Help Search Login Register  

Author Topic: Most common mistakes....  (Read 1785 times)

0 Members and 1 Guest are viewing this topic.

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Most common mistakes....
« 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:
Code: [Select]
_y = _this;
_x = _x + [_y];

Right:  :yes:
Code: [Select]
_y = _this;
_x = [];
_x = _x + [_y];
Code: [Select]
_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:
Code: [Select]
_x = _this;
while {"_i=0","_i=_i+1","_i<10"} do {
   _y =  _x + 1;
};
print format["%1",_y];
Code: [Select]
_x = _this;
if (_x>5) then {_y=10;} else {_y=1};
};
print format["%1",_y];

Right:  :yes:
Code: [Select]
_x = _this;
_y = 0;
while {"_i=0","_i=_i+1","_i<10"} do {
   _y =  _x + 1;
};
print format["%1",_y];
Code: [Select]
_x = _this;
_y = 0;
if (_x>5) then {_y=10;} else {_y=1};
print format["%1",_y];
« Last Edit: 24 Aug 2007, 20:15:03 by Mr.Peanut »
urp!

Offline LeeHunt

  • Former Staff
  • ****
  • John 21:25
Re: Most common mistakes....
« Reply #1 on: 24 Aug 2007, 23:14:21 »
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


Offline Nixer6

  • Members
  • *
Re: Most common mistakes....
« Reply #2 on: 25 Aug 2007, 02:33:16 »
Cool....  :cool2:

OnMapSingleClick

Wrong  :no:
Code: [Select]
OnMapSingleClick [];
Right  :yes:
Code: [Select]
OnMapSingleClick "";
In a trigger's On Activation Field

Wrong  :no:
Code: [Select]
onMapSingleClick "this={_pos} execVM "myScript.sqf";
Code: [Select]
onMapSingleClick "this="_pos" execVM (myScript.sqf);
Right  :yes:
Code: [Select]
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:
Code: [Select]
_pos = _this select 0;
hMove setPos [(_pos select 0),(_pos select 1),0];
heliPilot doMove _pos;

Right  :yes:
Code: [Select]
_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.  :)





« Last Edit: 29 Aug 2007, 20:07:08 by Mr.Peanut »
Why do I have to be a Rocket Scientist to make a good mission?

Offline LeeHunt

  • Former Staff
  • ****
  • John 21:25
Re: Most common mistakes....
« Reply #3 on: 25 Aug 2007, 14:33:49 »
this one is very helpful Nixer, i've made that "double effect" map click mistake  ::)

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: Most common mistakes....
« Reply #4 on: 25 Aug 2007, 19:33:59 »
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?
urp!

Offline Nixer6

  • Members
  • *
Re: Most common mistakes....
« Reply #5 on: 26 Aug 2007, 00:09:15 »
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.

Code: [Select]
// disable Map Single Clicks
[color=red]OnMapSingleClick[/color] "";
if embaressed [color=red]exitWith[/color] {};




« Last Edit: 29 Aug 2007, 09:52:12 by Nixer6 »
Why do I have to be a Rocket Scientist to make a good mission?

Offline hoz

  • OFPEC Site
  • Administrator
  • *****
Re: Most common mistakes....
« Reply #6 on: 29 Aug 2007, 06:12:34 »
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.


Xbox Rocks

Offline LeeHunt

  • Former Staff
  • ****
  • John 21:25
Re: Most common mistakes....
« Reply #7 on: 05 Sep 2007, 21:16:36 »
Still a bit confused by the above posts, what is the final way to run a map click and then disable it after clicking?

Offline Nixer6

  • Members
  • *
Re: Most common mistakes....
« Reply #8 on: 08 Sep 2007, 16:29:38 »
Simply in a script

Code: [Select]
arrayName=[];
OnMapSingleClick "arrayName=_pos";
OnMapSingleClick  "";

Hope that helps.  :yes:
Why do I have to be a Rocket Scientist to make a good mission?

Offline LeeHunt

  • Former Staff
  • ****
  • John 21:25
Re: Most common mistakes....
« Reply #9 on: 09 Sep 2007, 14:30:32 »
thanks!!!! :)