Need help with looping function for battle system (SOLVED)

Started by poc301, Fri 12/11/2004 14:09:04

Previous topic - Next topic

poc301

I have done a lot of reading through the forums and can't find anything helpful in this particular instance.Ã,  I am nearing completion of the first part of my Quest For Glory RPG to release a demo (the first city is done), and I was doing all kinds of testing, when I realized I left the automated battle system turned on (for those who don't like fighting, I have an automated system where the game fights for you, similar to QFG4).Ã,  Random is a great function :)

Anyways, when I turned the system back to manual, the thing didn't work as anticipated...Ã,  I keep getting loop errors.Ã,  So essentially, I need some code suggestions to get the looping function to work.Ã,  The system is turn based because I am a bigger fan of that than the realtime systems, but I guess I don't know how to make it wait for a character input to be made.Ã,  The user will be able to navigate 2 GUIs, a melee and spell GUI, and select the attack to be made.Ã,  But I can't make the game stop executing and wait for a selection to be made (I really hope I explained that clearly enough...)Ã,  Here is the skeleton code for what I am attempting to do:


function room_b() {
Ã,  // script for room: Player enters screen (after fadein)


//BATTLE SCRIPTING


GUIOn(7);Ã,  //TURN STAT GUI ON
GUIOn(9);Ã,  Ã,  //TURN MELEE BATTLE GUI ON

string turn;Ã,  Ã, //Reflects whose turn it is on the Stat GUI
int turn2;Ã,  Ã,  Ã, //Ã,  Determines whose turn it is.
turn2=Random(1);Ã,  // 0 for Hero, 1 for Monster
int damage;Ã,  // Damage done to the Hero
string gui;Ã,  //String used to update GUI
int mob;Ã,  Ã, //Monster type
int mobhp;Ã,  //Monster HP
int egohp;Ã,  //Hero HP
int herodone;Ã,  //If the hero is done with his turn.
int herodamage;Ã,  //Damage done by the hero


mob=GetGlobalInt(27);Ã,  //SET RANDOM DAMAGE DEALERS FOR SPECIFIC MOB
egohp=GetGlobalInt(14);

if (mob == 6){Ã,     //Silmaria Demon
Ã,  mobhp=25;      }



//---------------------ACTUAL FIGHT SYSTEM BELOW----------------


while (mobhp>0){Ã,  Ã,  Ã,  Ã,  Ã,  Ã, //RUNS THE SCRIPT UNTIL THE ENEMY IS DEAD


if (turn2==0){         //HERO TURN
StrFormat(turn, "Hero");
SetLabelText(7,1,turn);Ã,  Ã, 


if (egohp<1){
Display("You loose sucka!");Ã,  Ã,  Ã,  Ã,  Ã, //IF THE HERO DIES
QuitGame(0);
}

while(herodone==0){Ã,  Ã,  Ã, //THIS IS WHERE I NEED HELP.Ã,  Ã, I don't know what to do to make the game wait for a click on the GUI from the player before running the script below.

herodamage=(....);Ã,  //Calculation here for all the hero damage


mobhp=(mobhp-herodamage);


herodone++;
}

turn2++;
herodone=0;
}


else if (turn2==1){      //ENEMY TURN
StrFormat(turn, "Enemy");
SetLabelText(7,1,turn);Ã,  Ã, 

AnimateCharacter(GetGlobalInt(27),8,4,0);
while (character[GetGlobalInt(27)].animating != 0) {
Ã,  Wait(1);
}
FaceCharacter(GetGlobalInt(27), EGO);


if (mob == 6){Ã,     //Silmaria Demon
Ã,  damage=Random(4);}

if (damage>0){
AnimateCharacter(EGO, 15, 2, 0);
while (character[EGO].animating != 0) {
Ã,  Wait(1);
}
FaceCharacter(EGO, GetGlobalInt(27));
}

egohp=(egohp-damage);
SetGlobalInt(14, egohp);
turn2--;


}
}
}

Thanks,

Bill


Radiant

I believe the proper way to do this is not in a loop (because if the game is waiting on one script, it won't run other scripts (except rep_ex_al)).
So, stop your script at that point (have the function return), and have it continue when a GUI button is called (by calling the function once more, with anohter parameter)

poc301

Thanks!  That did the trick.  I had to rewrite the code to call functions instead of doing a loop, but I guess it makes more sense this way anyways :)


SMF spam blocked by CleanTalk