| Blockland Forums > Modification Help |
| Need to remove certain parts of an array |
| (1/2) > >> |
| Lugnut:
I have a file that looks like this --- Code: ---$C2CMultilist::NumEntries = 0; $C2CMultilist::user[$C2CMultilist::NumEntries++] = "White_Tiger"; $C2CMultilist::user[$C2CMultilist::NumEntries++] = "Lugnut1206"; $C2CMultilist::user[$C2CMultilist::NumEntries++] = "Derpington"; --- End code --- You get the idea. suppose I want to remove the line that reads like this: $C2CMultilist::user[$C2CMultilist::NumEntries++] = "Lugnut1206"; via a function or other method. I have the following code, undoubtedly missing something important, is there anything that someone would like to add? Updated: 3/4/12 1pm --- Code: ---function removeC2CGroupUser(%name) { %file = new FileObject(); %file.openForWrite("config/client/c2cgroup.cs"); for(%i = 0; %i < $C2CMultilist::NumEntries; %i++) { if($C2CMultilist::user[%i] $= %name) { $C2CMultilist::user[%i] = ""; %foundtarget = 1; } if(%foundtarget) { $C2CMultilist::user[%i--] = $C2CMultilist::user[%i--]; } else { %file.writeline("$C2CMultilist::user[$C2CMultilist::NumEntries++] = \"" @ $C2CMultilist::user[%i] @ "\";"); } } %file.close(); %file.delete(); } --- End code --- I.. uh.. haven't tested it yet, for a few real-world reasons. |
| Ipquarx:
I'm pretty sure that will crash when it finds a match. On another note, for the purpose you wan't it for, this would (assuming it worked), write all the variables BUT the one you specify to a file. This isn't a hugely efficient way of doing it. |
| phflack:
i'd suggest making a variable for the placement of it, and resetting the values after it to one behind them in a similar way you're setting them in the first place and then you'd want to subtract one from numentries |
| Treynolds416:
%foundtarget isn't defined. Also, that 'if' statement is invalid |
| Brian Smithers:
--- Quote from: Lugnut1206 on March 03, 2012, 04:24:50 PM --- --- Code: ---if(%foundtarget) --- End code --- --- Code: ---if(strstr($C2CMultilist::user[%i] $= %name) > -1) --- End code --- --- End quote --- The 2 things I listed are incorrect 1 - %foundtarget is not defined 2 - that is just so wrong, idk what it i supposed to do, but hell it's wrong. If you want to see if the $C2CMultilist::user[%i] is the %name, then just do if($C2CMultilist::user[%i] $= %name) |
| Navigation |
| Message Index |
| Next page |