Good Evening To All AGSer.
I have a terrible script that should be cleaned up quite a bit.
I just wrote an idea of what I would do... and apparently works well...
It's what I would do, but when I run the battle, my pc go in slow motion..
I certainly know because the script is not very readable in itself.
This happens to me quite often when I put a function repeatedly.
int time, firstcounter, secondcounter, thirdcounter, fourcounter, fivecounter, sixcounter, sevencounter, eightcounter,
ninecounter, tencounter;
bool pushed, released;
Enemy Monster[8];
function ShowTargetGUI()
{
GUIControl *theControl = GUIControl.GetAtScreenXY(mouse.x, mouse.y);
gTarget.Visible = true;
if (theControl == ButtonPush && mouse.IsButtonDown(eMouseLeft) && pushed) //button pushed
{
int i = 0;
while (i<NumeriCasuali(4, 6)){ time ++; i++;}
if (time > 5) { gTarget.BackgroundGraphic = 3; firstcounter = NumeriCasuali(1, 5); }
//why if i use 'else if' doesn't work ?!
if (time > 15) { gTarget.BackgroundGraphic = 4; secondcounter = NumeriCasuali(6, 15); }
if (time > 30) { gTarget.BackgroundGraphic = 5; thirdcounter = NumeriCasuali(16, 30); }
if (time > 45) { gTarget.BackgroundGraphic = 6; fourcounter = NumeriCasuali(31, 45); }
if (time > 60) { gTarget.BackgroundGraphic = 7; fivecounter = NumeriCasuali(46, 55); }
if (time > 75) { gTarget.BackgroundGraphic = 8; sixcounter = NumeriCasuali(56, 70); }
if (time > 90) { gTarget.BackgroundGraphic = 9; sevencounter = NumeriCasuali(71, 85); }
if (time > 100) { gTarget.BackgroundGraphic = 10; eightcounter = NumeriCasuali(86, 90); }
if (time > 110) { gTarget.BackgroundGraphic = 11; ninecounter = NumeriCasuali(91, 100); }
if (time > 120) { gTarget.BackgroundGraphic = 12; tencounter = NumeriCasuali(101, 115); }
if (time > 125) // (TIME OUT) IF STILL BUTTON PUSHED
{
//Enemy RECOVER ENERGY
if (Monster[1].ID[1] == cChar.ID && Monster[1].hp < 499) Monster[1].hp += 30;
// here 'else if' is okay
else if (Monster[2].ID[2] == cChar2.ID && Monster[2].hp < 699) Monster[2].hp += 30;
else if (Monster[3].ID[3] == cChar3.ID && Monster[3].hp < 899) Monster[3].hp += 30;
else if (Monster[4].ID[4] == cChar4.ID && Monster[4].hp < 1099) Monster[4].hp += 30;
else if (Monster[5].ID[5] == cChar5.ID && Monster[5].hp < 1299) Monster[5].hp += 30;
else if (Monster[6].ID[6] == cChar6.ID && Monster[6].hp < 1499) Monster[6].hp += 30;
else if (Monster[7].ID[7] == cChar7.ID && Monster[7].hp < 2499) Monster[7].hp += 30;
pushed = false;
Labelcounter.Text = " Time's up"; //time's up
Labelhit.Text = "You Failed";
cJack.Animate(1, 2, eOnce, eNoBlock, eForwards);
gTarget.BackgroundGraphic = 2; //turn to normal graphic
time = 0;
}
SetTimer(1, 30);
}
else if (released)
{
//LOW HIT
if (time > 5)
{ cJack.Animate(1, 2, eOnce, eNoBlock, eForwards);
Labelcounter.Text = String.Format("%d %", firstcounter); Labelhit.Text = "Low Hit"; }
if (time > 15)
{ Labelcounter.Text = String.Format("%d %", secondcounter); Labelhit.Text = "Low Hit"; }
if (time > 30)
{ Labelcounter.Text = String.Format("%d %", thirdcounter); Labelhit.Text = "Low Hit"; }
//MEDIUM HIT
if (time > 45)
{ Labelcounter.Text = String.Format("%d %", fourcounter); Labelhit.Text = "Medium Hit"; }
if (time > 60)
{ Labelcounter.Text = String.Format("%d %", fivecounter); Labelhit.Text = "Medium Hit"; }
if (time > 75)
{ Labelcounter.Text = String.Format("%d %", sixcounter); Labelhit.Text = "Medium Hit"; }
//HIGH HIT
if (time > 90)
{ Labelcounter.Text = String.Format("%d %", sevencounter); Labelhit.Text = "High Hit"; }
if (time > 100)
{ Labelcounter.Text = String.Format("%d %", eightcounter); Labelhit.Text = "High Hit"; }
//super hit
if (time > 110)
{ Labelcounter.Text = String.Format("%d %", ninecounter); Labelhit.Text = "Super Hit"; }
//CRITICAL HIT
if (time > 120)
{ Labelcounter.Text = String.Format("%d %", tencounter); Labelhit.Text = "Critical Hit"; }
//TIME OUT IF BUTTON IS RELEASED
if (time > 125)
{
Labelcounter.Text = "Time Out";
Labelhit.Text = "You Failed";
gTarget.BackgroundGraphic = 2;
time = 0;
}
time = 0;
}
Labelinfo.Text = String.Format("%d", time);
}
function Battaglia()
{
countingDown=true; //check if the 'timer battle' is expired or not
if (Monster[1].ID[1] == cChar.ID)
{
if (!mouse.IsButtonDown(eMouseLeft) ) //a pseudo - released performance
{
if (gTarget.BackgroundGraphic == 3) Monster[1].hp -= firstcounter;
else if (gTarget.BackgroundGraphic == 4) Monster[1].hp -= secondcounter;
else if (gTarget.BackgroundGraphic == 5) Monster[1].hp -= thirdcounter;
else if (gTarget.BackgroundGraphic == 6) Monster[1].hp -= fourcounter;
else if (gTarget.BackgroundGraphic == 7) Monster[1].hp -= fivecounter;
else if (gTarget.BackgroundGraphic == 8) Monster[1].hp -= sixcounter;
else if (gTarget.BackgroundGraphic == 9) Monster[1].hp -= sevencounter;
else if (gTarget.BackgroundGraphic == 10) Monster[1].hp -= eightcounter;
else if (gTarget.BackgroundGraphic == 11) Monster[1].hp -= ninecounter;
else if (gTarget.BackgroundGraphic == 12) Monster[1].hp -= tencounter;
else if (ButtonExtra.NormalGraphic == 68) TEMPO -= 5; //else if 'button failed' is visible >>> timer battle go down -5
}
}
function room_RepExec()
{
if (InitBattle ) //boolean go true by click a button, boolean go false by hp enemy <= 0
{ ShowTargetGUI(); Battaglia(); }
}
void on_event (EventType event, int data)
{
GUIControl*gc = GUIControl.GetAtScreenXY(mouse.x, mouse.y);
Button*b;
if (gc != null) b = gc.AsButton;
if (event == eEventEnterRoomBeforeFadein)
{ mouse.Visible = false; Labelcounter.Text = ""; Labelhit.Text = ""; b = ButtonPush; }
////////////// PUSHED BUTTON /////////////////////////////////////////
else if (event == eEventGUIMouseDown && b != null )
{
//Display("pushed");
pushed = true;
Labelcounter.Text = "";
ButtonExtra.Visible = false;
//ButtonExtra.X = 12;
Labelhit.Text = "";
released = false;
}
////////////// RELEASED BUTTON //////////////////////////////////////
else if (event == eEventGUIMouseUp && b != null )
{
//Display("REL");
SetTimer(1, 30);
pushed = false;
released = true;
gTarget.BackgroundGraphic = 2;
}
}
Someone could help me to clean up this terrible script ? ,(
and thanks in advance for your patience, also for reading this message post...
coordial greetings
"//why if i use 'else if' doesn't work ?!"
The "else if" does not work in the first case, because every condition also includes all the following ones:
time > 10 also means time > 5
time > 15 also means time > 10 and time > 5 etc.
Therefore "time > 5" will be true in all other cases as well.
What you should do is reverse conditions:
time < 10
time < 15, etc.
Yes, I know this does not answer you main question, but that's the first thing I noticed. :)
Thank you very much, Crimson Wizard, for giving me this vital aid.
I'm still a good noob, and this suggestion will make me start to improve better this terrible script...
Still, Thank you again