Jump to content
Sign in to follow this  
CarlGustaffa

Need help resolving a script problem

Recommended Posts

Hi

I'm working on (yet another) artillery script/addon thingy, mostly for fun. It is supposed to do some nice radiochatter depending on many factors. The problem I currently have is this: When I prebuild an array of strings that are send into the script, everything works. However, when I send in something built automatically, it fails. The really weird (to me) problem is that when I check what goes in, they are identical. Yet one works, the other fails. Script as follows:

//indexselect and speechlist must be global to work with spawn? Unless _indexselect is created automatically.
indexselect = [
"o01",
"o02_0","o02_1","o02_2","o02_3","o02_4","o02_5","o02_6","o02_7","o02_8","o02_9","o02_grid","o02_over",
"o03_units",
"o04_guns","o04_message","o04_out","o04_rounds","o04_targetnumber",
"o05_shot",
"o06_splash",
"o07_correct","o07_impact",
"o08_end",
"s01",
"s02_0","s02_1","s02_2","s02_3","s02_4","s02_5","s02_6","s02_7","s02_8","s02_9","s02_grid","s02_out",
"s03_units",
"s04_guns","s04_message","s04_over","s04_rounds","s04_targetnumber",
"s05_shot",
"s06_splash",
"s07_correct","s07_impact",
"s08_end"
];
speechlist = [
["o01","Steel Rain, this is Raptor. Adjust fire, system aided. Over",4],
["o02_0","0",0.345],
["o02_1","1",0.345],
["o02_2","2",0.345],
["o02_3","3",0.345],
["o02_4","4",0.345],
["o02_5","5",0.345],
["o02_6","6",0.345],
["o02_7","7",0.345],
["o02_8","8",0.345],
["o02_9","9",0.345],
["o02_grid","Grid ",0.345],
["o02_over","Over.",0.345],
["o03_units","Units in the open. Request splash. Over",0.345],
["o04_guns"," guns in effect.",0.345],
["o04_message","Message to observer: ",0.345],
["o04_out","Out.",0.345],
["o04_rounds"," rounds, ",0.345],
["o04_targetnumber","Target number Alpha Bravo ",0.345],
["o05_shot","Shot. Out.",0.345],
["o06_splash","Splash. Out.",0.345],
["o07_correct","Correct and fire for effect. Over.",0.345],
["o07_impact","Impact grid",0.345],
["o08_end","Record as target. End of mission. Targets supressed. Over",0.345],
["s01","Raptor this is Steel Rain. Adjust fire, system aided. Out",0.345],
["s02_0","0",0.345],
["s02_1","1",0.345],
["s02_2","2",0.345],
["s02_3","3",0.345],
["s02_4","4",0.345],
["s02_5","5",0.345],
["s02_6","6",0.345],
["s02_7","7",0.345],
["s02_8","8",0.345],
["s02_9","9",0.345],
["s02_grid","Grid",0.345],
["s02_out","Out.",0.345],
["s03_units","Units in the open. Request splash. Out.",0.345],
["s04_guns","guns in effect.",0.345],
["s04_message","Message to observer: ",0.345],
["s04_over","Over",0.345],
["s04_rounds","rounds",0.345],
["s04_targetnumber","Target number Alpha Bravo",0.345],
["s05_shot","Shot. Over.",0.345],
["s06_splash","Splash. Over.",0.345],
["s07_correct","Correct and fire for effect. Out",0.345],
["s07_impact","Impact grid",0.345],
["s08_end","Record as target. End of mission. Targets supressed. Out.",0.345]
];

_speakthis = {
private ["_i","_array","_string","_delay","_index","_who","_indexselect"];
_array = _this;
_index = 0;
_string = "";
_delay = 0;
_indexselect = [];
/*
//Probably not a good idea to create this array every time something is said.
for "_i" from 0 to count speechlist - 1 do {
	_indexselect = _indexselect + [(speechlist select _i) select 0];
	player globalChat format ["%1", _indexselect];
};
*/
for "_i" from 0 to count _array - 1 do {
	_index = indexselect find (_array select _i);
//		_index = ((speechlist select _i) select 0) find (_array select _i);
	_string = _string + format ["%1", format["%1", (speechlist select _index) select 1]];
	_delay = _delay + ((speechlist select _index) select 2);
//		player say ((speechlist select _index) select 0);
};
_who = (if (toArray (_array select 0) select 0 == 111) then {"O: "} else {"S: "});
if (_who == "O: ") then {
	player sideChat format [_who + "%1", _string];
} else {
	[west,"Airbase"] sideChat format [_who + "%1", _string];
};
sleep _delay;
};

_numberToLookup = {
private ["_i","_gridarray","_ret","_string","_who","_retdelay","_delay"];
_ret = [];
_retdelay = 0;
_who = _this select 0;
_gridarray = toArray (_this select 1);
for "_i" from 0 to count _gridarray - 1 do {
	switch (_gridarray select _i) do {
		case 48 : {_string = format ["%1", _who + "02_0"]};
		case 49 : {_string = format ["%1", _who + "02_1"]};
		case 50 : {_string = format ["%1", _who + "02_2"]};
		case 51 : {_string = format ["%1", _who + "02_3"]};
		case 52 : {_string = format ["%1", _who + "02_4"]};
		case 53 : {_string = format ["%1", _who + "02_5"]};
		case 54 : {_string = format ["%1", _who + "02_6"]};
		case 55 : {_string = format ["%1", _who + "02_7"]};
		case 56 : {_string = format ["%1", _who + "02_8"]};
		case 57 : {_string = format ["%1", _who + "02_9"]};
	};
	_ret = _ret + [_string];
};
_ret;
};

_speech = ["o02_5","o04_guns"] spawn _speakthis; waitUntil {scriptDone _speech}; hint "I'm finished";

_returnarray = ["S","069138"] call _numberToLookup;
_yyy = ["s02_grid"];
_yyy = _yyy + _returnarray;
//_yyy = ["s02_grid","s02_0","s02_6","s02_9","s02_1","s02_3","s02_8"];
player globalChat format ["%1", _yyy];
_yyy call _speakthis;

Run script as it is directly from init.sqf as [] execVM "speak.sqf"; and observe the error. Take a screenshot. Now, uncomment the last comment which builds the same array of strings directly. Run it again, without the error. Take a screenshot. Compare the screenshot and see that the excact same stuff goes into the function.

Can anyone spot my mistake?

Share this post


Link to post
Share on other sites

Replace the "S" in

_returnarray = ["S","069138"] call _numberToLookup

with a small "s" and everything will be fine :)

_returnarray = ["s","069138"] call _numberToLookup

Xeno

Share this post


Link to post
Share on other sites

And thus the problematic one-liner grid chat becomes:

_speech = ["s02_grid"] + (["s", _grid] call _numberToLookup) spawn _speakthis; waitUntil {scriptDone _speech};

Thanks. Problem solved. I could kiss you. How on earth did you manage to spot that? :)

Share this post


Link to post
Share on other sites
How on earth did you manage to spot that? :)

I put my right hand on my monitor, said a magic formula and then it was obvious.

:smileflower:

Xeno

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  

×