siggy 10 Posted September 14, 2010 Hey folks. Apologies if I am posting in the wrong place! I'm having a bit of trouble with a switch statement that I've put into an SQF script and am hoping if someone is able to spot what I'm doing wrong? I've added a killed event handler to allUnits with the following in the init line of the player: {_x addEventHandler ["killed", {[(_this select 0),(group (_this select 0))] execVM "Killed.sqf";}];} forEach allUnits; This is a SP mission and the idea is to keep replacing units within a group from a random array of units. Here's Killed.sqf... _killed = _this select 0; _group = _this select 1; _soldier = switch (faction _killed) do { case RU: {RU_array select (random ((count RU_array) -1))}; case USMC: {USMC_array select (random ((count USMC_array) -1))}; case BIS_US: {US_array select (random ((count US_array) -1))}; case BIS_BAF: {BAF_array select (random ((count BAF_array) -1))}; case BIS_TKA: {TKA_array select (random ((count TKA_array) -1))}; }; //hintSilent format ["%1",(faction _killed)]; _soldier createUnit [(getMarkerPos "spawnPos"),_group,"this addEventHandler [""killed"",{[(_this select 0),(group (_this select 0))] execVM ""Killed.sqf""}];"]; exit; I'm just trying to get the basic script working ATM. Arrays for each faction are defined in the init.sqf file. "spawnPos" is an empty marker on the map etc. If I uncomment out the hintSilent, it correctly shows me the faction of the dead unit (which should match one of the cases!) though I get no replacement unit unless I replace the entire switch statement with a generic: _soldier = faction_array select (random ((count faction_array) -1)); I've been doing simple little scripts since the days of OFP but I can't figure this one out! It's like the returned faction doesn't match any of the cases?? I have examined examples in NORRIN's revive scripts and the breifing.sqf files and can't see what the problem is :( Any help is much appreciated! Share this post Link to post Share on other sites
Woodpeckersam 18 Posted September 15, 2010 (edited) I'm not completely sure if this is the reason but remove faction from this _soldier = switch (faction _killed) do To _soldier = switch (_killed) do Because a switch only occurs when a value/string has been added to a variable. So if _killed = RU then do case RU: {}; If that does not work then try this... switch (_killed) do If thAt doesn't work then I may be missing out the point of your script. Maybe if you havent got the application called "Squint" go ahead and download it, then add entire mission folder to project and note down any errors in the code. Ps. I typed this on my iPod touch so that could be the reason I'm missing the point lol. ---------- Post added at 01:52 AM ---------- Previous post was at 01:39 AM ---------- _havesquint = 0; switch (_havesquint) do { case 0: { siggy = [] execWWW "http://forums.bistudio.com/showthread.php?t=105860"; siggy action ["Download Squint", siggy]; }; case 1: { siggy sideChat "I already have Squint"; sleep 6.2; WoodyUk sideChat "Cool :D I love this script to check if you got it or not!"; }; }; Of course you dont have to have it, if you dont want to. Edited September 15, 2010 by WoodyUK Share this post Link to post Share on other sites
siggy 10 Posted September 15, 2010 Thanks WoodyUK, _killed is the name of unit that was killed. "faction _killed" returns the faction of that unit as a value to show whether they're BAF, USMC or CDF (who are all BLUFOR). The hintSilent I used as a debug to shows that this returns a value correctly (and these are the values I've then added for each case). The switch needs to use this faction of the dead unit to then pick a random replacement from the relevant array. Sample Briefing.sqf: // A2BM W  € € 110 // DO NOT EDIT THIS FILE waitUntil {!(isNull player)}; waitUntil {player==player}; switch (side player) do { case WEST: { player createDiaryRecord ["Diary",["briefing","As the tensions grow between Takistan and NATO about arms control of a WMD (Weapons of Mass Destruction), Alliance decided to take a further actions. Couple squadrons of fighter aircrafts and helicopters are situated in the <marker name='military_base_west'>Military Base</marker> near border with Takistan. Takistani Armed Forces believe that the first step is made...<br/> In order to prevent first strike, Takistani Armed Forces Command order to one "L-39 Albatros" squadron to take-off from the <marker name='airfield_east'>airfield</marker> near Loy Manara and move toward <marker name='military_base_west'>Miltary Base</marker> near Rasman in order to remove the threat."]]; }; case EAST: { }; case RESISTANCE: { }; case CIVILIAN: { }; }; ---------- Post added at 02:45 AM ---------- Previous post was at 02:07 AM ---------- Sorted! Squint warned that the comparing strings in switches was case sensitive. The case was correct however as I'm comparing to a string, made me think that the values for each case should be enclosed in quotes: _soldier = switch (faction _killed) do { case "RU": {RU_array select (random ((count RU_array) -1))}; case "USMC": {USMC_array select (random ((count USMC_array) -1))}; case "BIS_US": {US_array select (random ((count US_array) -1))}; case "BIS_BAF": {BAF_array select (random ((count BAF_array) -1))}; case "BIS_TKA": {TKA_array select (random ((count TKA_array) -1))}; }; Schoolboy error! Thanks :) Share this post Link to post Share on other sites