Home   Help Search Login Register  

Author Topic: Script stops working  (Read 2377 times)

0 Members and 1 Guest are viewing this topic.

Offline SaS TrooP

  • Members
  • *
  • n00b always & everywhere
Script stops working
« on: 10 Apr 2010, 20:50:12 »
Together with my friend we have created a script. Its goal is to randomly arm soldiers with one of 15 weapons and then randomly generate number of magazines they have.

Here's the original:
http://pastebin.com/jhQT7UUB

[script was converted from .sqs]

And then added these mags, fixed some minor errors (grenade bug) and added weapons:

Code: [Select]
//////////////////////////////////////////////////////////////////
// Function file for Armed Assault
// Created by: SaS TrooP
//////////////////////////////////////////////////////////////////


private ["_magazine","_weapon","_handgrenade","_magcount"];

 

_unit = _this select 0;
_liczba = round (random 15);

waitUntil {sleep 1; !isNull (findDisplay 46)};

switch (_liczba) do {

case 0: {
_magazine = "7Rnd_50_AE";
_weapon = "RH_deagle";
 _handgrenade = "HandGrenade_West";
 _magcount = round (RANDOM 5) + 3;
 
};

case 1: {
_magazine = "8Rnd_9x19_Mk";
_weapon = "RH_mk22";
_handgrenade = "";
_magcount = round (RANDOM 5) + 3;


};

case 2: {_magazine = "8Rnd_9x19_Mksd"; _weapon = "RH_mk22sd";
_magcount = round (RANDOM 5) + 3;};

case 3: {_magazine = "15Rnd_9x19_usp"; _weapon = "RH_usp";
_magcount = round (RANDOM 5) + 3;};

case 4: {_magazine = "12Rnd_45cal_usp"; _weapon = "RH_uspm";
_magcount = round (RANDOM 5) + 3;};

case 5: {_magazine = "8Rnd_45cal_m1911"; _weapon = "RH_m1911";
_magcount = round (RANDOM 5) + 3;};

case 6: {_magazine = "8Rnd_45cal_m1911"; _weapon = "RH_m1911sd";
_magcount = round (RANDOM 5) + 3;};

case 7: {_magazine = "8Rnd_45cal_m1911"; _weapon = "RH_m1911old";
_magcount = round (RANDOM 5) + 3;};

case 8: {_magazine = "15Rnd_9x19_M9"; _weapon = "15Rnd_9x19_M9";
_magcount = round (RANDOM 5) + 3;};

case 9: {_magazine = "17Rnd_9x19_g17"; _weapon = "rh_g17";
_magcount = round (RANDOM 5) + 3;};

case 10: {_magazine = "19Rnd_9x19_g18"; _weapon = "rh_g18";
_magcount = round (RANDOM 5) + 3;"};

case 12: {_magazine = "8Rnd_762_tt33"; _weapon = "rh_tt33";
_magcount = round (RANDOM 5) + 3;};

case 13: {_magazine = "20Rnd_32cal_vz61"; _weapon = "rh_vz61";
_magcount = round (RANDOM 5) + 3;};

case 14: {_magazine = "30Rnd_9x19_tec"; _weapon = "rh_tec9";
_magcount = round (RANDOM 5) + 3;};

case 15: {_magazine = "32Rnd_9x19_Muzi"; _weapon = "rh_Muzi";
_magcount = round (RANDOM 5) + 3;};

};

removeAllWeapons _unit;
for "_i" from 1 to _magcount do {_unit addMagazine _magazine};
if (_handgrenade != "") then {_unit addMagazine _grenade};
_unit addWeapon _weapon;

Both scripts were started with:
uzbr = [this]/this execVM "script.sqf";

And then, on the second script, I receive a message:
Quote
Type object, needed field, config entry
[translated, I am not pretty sure how its in english ArmA2]

What I am doing wrong so I receive that message?

Offline Wolfrug

  • Addons Depot
  • Former Staff
  • ****
  • Official OFPEC Old Timer
Re: Script stops working
« Reply #1 on: 11 Apr 2010, 21:21:23 »
What's the full error message? It usually tells you WHERE exactly in the script the error occurs, which will help us track it down. Quickly reading through it I don't see any errors, but I'm really blind to that, so...

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

Offline SaS TrooP

  • Members
  • *
  • n00b always & everywhere
Re: Script stops working
« Reply #2 on: 13 Apr 2010, 16:37:27 »
Line 11, probably something around _unit definition or _liczba.
I have header as you probably cant see, I am not sure if game reports line of header as well.

Offline Wolfrug

  • Addons Depot
  • Former Staff
  • ****
  • Official OFPEC Old Timer
Re: Script stops working
« Reply #3 on: 15 Apr 2010, 14:28:24 »
Hi,

I don't know, the error message is a bit strange O.o I guess you run it [unitname] execvm "script.sqf", right? The only thing I can imagine being the problem is the
Code: [Select]
waitUntil {sleep 1; !isNull (findDisplay 46)}; line, the purpose of which eludes me. What are you trying to do there? Does the script work if you remove it?

Sorry that I can't be of any more help. Whenever I debug a script, I use lots of "hint str (_var)"'s to make sure the variables are getting properly assigned, hints throughout the script to figure out how far it's going, and then I obviously remove and change things that I think might not be working out. Usually I spend hours only to track down a missing ; or a typo inside some larger whole  :dry: But that's debugging for you...

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

Offline SaS TrooP

  • Members
  • *
  • n00b always & everywhere
Re: Script stops working
« Reply #4 on: 16 Apr 2010, 16:03:14 »
There are no changes after that line -.-
I am not good enough to write solo scripts with real mathematical thinking (man, I write books :P)

Other way: I need a new script. Originally, I wanted to use only _unit and _liczba while executing normal switch script, which rolls one of cases, where weapon and magazines are set up manually. But later I found that more random would be drawing of number of magazines.

I will modify the script and put it here later, with "kits" ready. Can you tell me what to do to randomly roll number of magazines?

EDIT: Here it goes...
Quote
//////////////////////////////////////////////////////////////////
// Function file for Armed Assault
// Created by: SaS TrooP
//////////////////////////////////////////////////////////////////

_unit = _this select 0;
_liczba = floor (random 16);
removeallweapons _unit;

switch (_liczba) do

{

   case 1:
   {
      _unit addweapon "RH_deagle";
   };
   
   case 2:
   {
      _unit addweapon "RH_mk22";
   };
      case 3:
   {
      _unit addweapon "RH_mk22sd";
   };
      case 4:
   {
      _unit addweapon "RH_usp";
   };
      case 5:
   {
      _unit addweapon "RH_uspm";
   };
         case 6:
   {
      _unit addweapon "RH_m1911";
   };
         case 7:
   {
      _unit addweapon "RH_m1911sd";
   };
         case 8:
   {
      _unit addweapon "RH_m1911old";
   };
         case 9:
   {
      _unit addweapon "RH_m9";
   };
            case 10:
   {
      _unit addweapon "RH_g17";
   };
            case 11:
   {
      _unit addweapon "RH_g18";
   };
            case 12:
   {
      _unit addweapon "RH_tt33";
   };
            case 13:
   {
      _unit addweapon "RH_vz61";
   };
            case 14:
   {
      _unit addweapon "RH_tec9";
   };
               case 15:
   {
      _unit addweapon "RH_muzi";
   };            
               case 16:
   {
      _unit addweapon "RH_pm";
   };
   
};
   
« Last Edit: 16 Apr 2010, 16:36:55 by SaS TrooP »

Offline ModestNovice

  • Members
  • *
Re: Script stops working
« Reply #5 on: 18 Apr 2010, 23:38:06 »
I think the problem is that _magazine, _weapon, etc... are defined only inside the switch statement so they wouldn't have values outside of the switch statement. Try this:

Code: (kitGenerator.sqf) [Select]
private ["_unit","_kits","_kitCount","_kit","_magCount"];
_unit = _this select 0;

_kits =
[
["RH_deagle", "7Rnd_50_AE", "HandGrenade_West"],
["RH_mk22", "8Rnd_9x19_Mk", ""],
["RH_mk22sd", "8Rnd_9x19_Mksd", ""],
["RH_usp", "15Rnd_9x19_usp", ""],
["RH_uspm", "12Rnd_45cal_usp", ""],
["RH_m1911", "8Rnd_45cal_m1911", ""],
["RH_m1911sd", "8Rnd_45cal_m1911", ""],
["RH_m1911old", "8Rnd_45cal_m1911", ""],
["RH_m9", "15Rnd_9x19_M9", ""],
["RH_g17", "17Rnd_9x19_g17", ""],
["RH_g18", "19Rnd_9x19_g18", ""],
["RH_tt33", "8Rnd_762_tt33", ""],
["RH_vz61", "20Rnd_32cal_vz61", ""],
["RH_tec9", "30Rnd_9x19_tec", ""],
["RH_muzi", "32Rnd_9x19_Muzi", ""]
];

_kitCount = count _kits;
_kit = _kits select (round(random(_kitCount - 1)));
_magCount = (round (random 5)) + 3;

removeAllWeapons _unit;
_unit addWeapon (_kit select 0);

for "_i" from 1 to _magCount do
{
_unit addMagazine (_kit select 1);
};

if ((_kit select 2) != "") then
{
_unit addMagazine (_kit select 2);
};
« Last Edit: 18 Apr 2010, 23:42:34 by DaChevs »
"The road became empty and the people disappeared. The clouds ran away; opened up the sky, and one by one I watched every constellation die."
- Sean "Slug" Daley

Offline SaS TrooP

  • Members
  • *
  • n00b always & everywhere
Re: Script stops working
« Reply #6 on: 23 Apr 2010, 14:31:01 »
We have a progress, no bugs are shown on mission start, but player does not receive any weapon :S
I start the script with uzbr = [unitname] execvm "script.sqf";

When I start without [] but jumps off, but from that what I know selects 0 should always be stared with [].
I checked the script for some single letter mistakes. This is what Arma.rtp returns:

Code: [Select]
0:18:53,249 (0:00:00,000) [x\cba\addons\common\init.sqf:4] MISSINIT: missionName=erpeg_namalsk, worldName=namalsk, isMultiplayer=false, isServer=true
1133.27 (0) XEH: PostInit Started
1134.9 (0) XEH: PostInit Finished
Error in expression <unt","_kit","_magCount"];
_unit = _this select 0;

_kits =
[
["RH_deagle", "7Rn>
  Error position: <select 0;

_kits =
[
["RH_deagle", "7Rn>
  Error select: Typ Obiekt, potrzebny Pole,Config entry

Offline Inkompetent

  • Members
  • *
Re: Script stops working
« Reply #7 on: 24 Apr 2010, 13:24:35 »
Try adding a short sleep (like sleep 0.01;) in the beginning of the script. The problem is probably that the script tries to replace the weapon on the unit before it is allowed/able to do so by the engine. By adding the sleep the rest of the code in the script is postponed to not run until after the briefing screen, i.e. when you actually 'enter the character'.

That's the only thing I can think of really, because the script looks correct to me. And yes, you are right with the use of []-wrappers. When used you have to use the _this select X;-stuff since you've passed the script an array.

Offline ModestNovice

  • Members
  • *
Re: Script stops working
« Reply #8 on: 27 Apr 2010, 06:00:40 »
I've tested this script without a sleep and it works perfectly the same way SaS Troop is using it. Are you sure you are running RH Weapons pack???
"The road became empty and the people disappeared. The clouds ran away; opened up the sky, and one by one I watched every constellation die."
- Sean "Slug" Daley

Offline SaS TrooP

  • Members
  • *
  • n00b always & everywhere
Re: Script stops working
« Reply #9 on: 30 Apr 2010, 16:27:00 »
Well, I must say I am... suprised? :D

I added sleep 2; in the very beggining of the script and it seems to be working. I will update this topic if anything goes wrong, but looks OK right now!

BTW, dont you whink its little crappy, that we have to wait for engine initialization with such simple thing as weapon change?

Offline Inkompetent

  • Members
  • *
Re: Script stops working
« Reply #10 on: 02 May 2010, 01:50:04 »
It is a bit crappy - yes. But also understandable that the engine doesn't postpone and queue commands, since it wouldn't know which commands to queue. Maybe you want to do something with the weapon you've given the unit at another line of code, but how should the engine know to postpone that line as well?

A *very* good read with stuff researched/compiled by Sickboy can be found here: http://community.bistudio.com/wiki/6thSense.eu:EG

It pretty much lists in detail when the engine does what, and lots of stuff that's good to know for multiplayer scripting.