Fixed - I split the code into three smaller functions that call each other and added 'break' statements instead of the 'continue' ones. One of these fixed the problem, I don't know which. Thanks for helping, Trader.
Sometimes in the Wrench Events mod, when I press the Delete button next to one of the events in the menu (The X) the game freezes for no reason, and crashes.
Code in current release
function killWrenchEvent(%num)
{
for(%i=0;%i<10;%i++)
{
if(%i $= %num){%ms[%i] = "kill";continue;}
%ms[%i] = (isObject(%a=("txtWrenchEventTime_sec" @ %i)) ? %a.getValue() : "kill");
%ev[%i] = (isObject(%a=("selWrenchEventTime_sel" @ %i)) ? %a.getText() : "kill");
if(isObject("selWrenchEventTime_sel" @ %i))
{
for(%j=0;%j<5;%j++)
{
%p[%i,%j] = (selWrenchEventTime_sel @ %i).ev[%j];
}
}
}
%setnum = 0;
clientcmdClearWrenchEvents();
for(%i=0;%i<10;%i++)
{
if(%setnum $= %num){%setnum++;}
if(%ms[%i] !$= "kill")
{
clientcmdWrenchEventGUIRow(%ms[%i]*100,%ev[%i],%p[%i+%setnum,0],%p[%i+%setnum,1],%p[%i+%setnum,2],%p[%i+%setnum,3],%p[%i+%setnum,4]);
}
}
}
Code in my test version, slight edit
function killWrenchEvent(%num)
{
echo("Kill " @ %num);
//clientcmdWrenchEventGUIRow(%ms,%ev,%p0,%p1,%p2,%p3,%p4,%apply,%applyname)
%temp = new ScriptObject(){class = WrenchEvDeleteCtrlSO;count = 0;};
echo(">Save Events");
for(%i=0;%i<10;%i++)
{
if(%i == %num){continue;}
echo(%i);
if(!isObject(("txtWrenchEventTime_txt" @ %i))){continue;}
%txt = ("txtWrenchEventTime_txt" @ %i);
%txtB = ("txtWrenchEventTime_txt" @ %i @ "b");
%sec = ("txtWrenchEventTime_sec" @ %i);
%sel = ("selWrenchEventTime_sel" @ %i);
%kill = ("butWrenchEventTime_kill" @ %i);
%str = %sec.getValue()*100 TAB %sel.getText() TAB %sel.ev0 TAB %sel.ev1 TAB %sel.ev2 TAB %sel.ev3 TAB %sel.ev4 TAB %sel.apply TAB %sel.applyname;
%temp.addValue(%str);
%sel.clear();
}
clientcmdclearwrenchevents();
%temp.dumpStack();
echo(">Readd Stuff");
for(%i=0;(%i<10 && %temp.value[%i] !$= "");%i++)
{
%s = %temp.getValue(%i);
echo(%i SPC getField(%s,1));
clientcmdWrenchEventGUIRow(getField(%s,0),getField(%s,1),getField(%s,2),getField(%s,3),getField(%s,4),getField(%s,5),getField(%s,6),getField(%s,7),getField(%s,8));
}
%temp.delete();
}
When I replaced the clientcmdclearwrenchevents(); parts with another for() loop to delete each button/control manually with echoes between them, it seemed to crash as it was deleting selWrenchEventTime_sel. (The select box where you select which event to have) Other times, while it was 'Saving' the parameters and variables for the events.
Probably from the same cause, sometimes, the Delete button for random events just disappears for no reason if you delete several events in quick succession.
My problem is: How can I make this 'Delete' button work without risk of crashing the game?
Also, if you can answer it, why does this happen?