Jump to content
Sign in to follow this  
Entelin

Need help with this simple script im making.

Recommended Posts

The unit spawns the hints are all displayed, however the unit will not move to convoyendpos, and does not become equipped with the M9. This is my first script, the final idea is simply to have this unit enter a truck, and drive somewhere, respawn when it dies and repeat. I'm trying this basic thing first though.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">sleep(3);

hint "Add unit";

_convoyGroup = createGroup Civilian;

_convoydriver = "Civilian7" createUnit [getpos convoystartpos,_convoyGroup,"_convoyDriver = this", 1.0, "PRIVATE"];

processInitCommands;

sleep(2);

hint "move";

_convoyDriver doMove getpos convoyendpos;

removeAllWeapons _convoydriver;

_convoyDriver addWeapon "M9";

_convoyDriver addMagazine "15Rnd_9x19_M9";

_convoyDriver addMagazine "15Rnd_9x19_M9";

hint "end";

Share this post


Link to post
Share on other sites

Threads about mission editing/scripting belong in the mission editing and scripting forum, moving.

Share this post


Link to post
Share on other sites
The unit spawns the hints are all displayed, however the unit will not move to convoyendpos, and does not become equipped with the M9. This is my first script, the final idea is simply to have this unit enter a truck, and drive somewhere, respawn when it dies and repeat. I'm trying this basic thing first though.

try:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

sleep(3);

hint "Add unit";

_convoyGroup = createGroup Civilian;

;**_convoydriver = "Civilian7" createUnit [getpos convoystartpos,_convoyGroup,"_convoyDriver = this", 1.0, "PRIVATE"];

convoyDriver = objNull

"Civilian7" createUnit [getpos convoystartpos,_convoyGroup,"convoyDriver = this", 1.0, "PRIVATE"];

@!isNull convoyDriver

_convoyDriver = convoyDriver

processInitCommands;

sleep(2);

hint "move";

_convoyDriver doMove getpos convoyendpos;

removeAllWeapons _convoydriver;

_convoyDriver addMagazine "15Rnd_9x19_M9";

_convoyDriver addMagazine "15Rnd_9x19_M9";

_convoyDriver addWeapon "M9";

hint "end";

1. no use of local vars in init string

2. addWeapon after addMagazine

3. processInitCommands only for JIP players to see inits on already created units (works a bit crappy if you ask me)

Share this post


Link to post
Share on other sites

So prefixing a variable with _ makes it local? does having a variable defined within a {} block make any difference in scope? I Changed my code to this and it works fine, just got rid of the _'s and changed the item add order like you said. The driver should be a global because I might want to refer to it in another script. Any problems here?

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">sleep(3);

hint "Add unit";

convoyGroup = createGroup Civilian;

"Civilian7" createUnit [getpos convoystartpos,convoyGroup,"convoyDriver = this", 1.0, "PRIVATE"];

processInitCommands;

sleep(2);

hint "move";

convoyDriver doMove getpos convoyendpos;

removeAllWeapons convoydriver;

convoyDriver addMagazine "15Rnd_9x19_M9";

convoyDriver addMagazine "15Rnd_9x19_M9";

convoyDriver addWeapon "M9";

hint "end";

Share this post


Link to post
Share on other sites
So prefixing a variable with _ makes it local? does having a variable defined within a {} block make any difference in scope?

Yes, the underscore _ does make a variable "local" in this scripting language.

Yes, defining a local variable inside a scope formed by curled braces {} makes a difference. The variable is only visible inside that scope. My opinion is that when you write scripts, you should define your variables in the innermost scope it is used in. Opposite to this would be to have all variables global.

The "scoping" and the function private make it possible that you can have in one script two or more different variables having exactly the same name - if they are not in the same scope. Do not abuse this feature though, as it reduces the readability of your script.

Familiarize yourself with OFPEC tags. You should get one for yourself if you get more into OFP/ArmA mission or addon making. It should be used for all global identifiers. It is a way to avoid naming clashes.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×