Scripting driving me nuts! I swear I can't find a problem with this. (SOLVED)

Started by poc301, Thu 23/12/2004 18:42:39

Previous topic - Next topic

poc301

Hello all.Ã,  This is the EGOTURN() function for use with my battle system.Ã,  For some reason whenever the code gets to the AnimateCharacterEx command for the attack code, it just stops and sits there, like it isn't ending.Ã,  The character hits the first frame of the animation (or so it seems), but then no animation happens on the screen.Ã,  I checked the loop and there are no delays on it or anything.Ã,  Any ideas would be appreciated.

EDIT: On a sidenote, I found that if I turn the final 1 at the end of the AnimateCharacterEx code to a 0 (so it doesn't wait for the animation to finish), the whole thing works fine, but the thing goes too fast to see the animations.



function egoturn() {
int mobhp;
int dmg;


mobhp=(GetGlobalInt(13));

if (GetGlobalInt(9) == 2){ //Attack

AnimateCharacterEx(0, 8, 3, 0, 0, 1);
AnimateCharacterEx(9, 15, 1, 0, 0, 1);
AnimateCharacterEx(9, 14, 1, 0, 0, 1);
AnimateCharacterEx(9, 0, 1, 0,0,0);

dmg=Random(5);



}Ã,  //CLOSE ATTACK BRACKET


mobhp=(mobhp-dmg);
SetGlobalInt(13, mobhp);
enemyturn();

}Ã,  //Close EgoTurn Bracket



Thanks guys!

Bill

poc301

More info I just found out...

I changed the first animation method to this :

AnimateCharacter(EGO, 8, 3, 0);
while (character[EGO].animating != 0) {
  Wait(1);


And this time it bombed out on line 108, which is :

Wait(1);

Could there be something not letting the computer run the wait command??  This is odd...

Pumaman

When you say "it bombed out", what exactly do you mean? was there an error message?

poc301

Sorry, bad choice of words...  It just stops.  The watch icon appears, like its animating, but no animating happens. 

I ALT X to get out of it and it says it stopped on Line 109 or whatever the Wait command is on.

As I said, if I remove the wait command it all works fine.

The wait command works fine up to this point too.  This script is in the Global Script, but all wait commands for animations in GUI scripts, and in rooms all work fine.  Its odd.

RickJ

The problem is that each the AnimateCharacterEx() statements only make a request to the engine to do so, and the requests are not queued.   So when you execute a series of AnimateCharacter() statements, on the same character only the last one will actually do anything.   You could try something like the following to see what I mean:
Code: ags

:
:
if (GetGlobalInt(9) == 2){ //Attack
   AnimateCharacterEx(0, 8, 3, 0, 0, 1);
   Wait(200);
   AnimateCharacterEx(9, 15, 1, 0, 0, 1);
   Wait(200);
   AnimateCharacterEx(9, 14, 1, 0, 0, 1);
   Wait(200);
   AnimateCharacterEx(9, 0, 1, 0,0,0);
   Wait(200);
   dmg=Random(5);
}  //CLOSE ATTACK BRACKET
:


A similar thing happens when you use the while statement.  Since your script hasn't completed it's execution and returned to the engine the character hasn't yet started to animate, and consequently your while condition is never met.


Gilbert

Quote from: RickJ on Fri 24/12/2004 02:37:30
The problem is that each the AnimateCharacterEx() statements only make a request to the engine to do so, and the requests are not queued.
I don't think so, AnimateCharacter(EX) () functions are executed immediately, and since he set the first three animations to BLOCKING, the animations should be played one by one perfectly. (tested)

I think he just said the animations were too fast, in that case just try to increase the delay for eact animation so they'll be played slower.
If it's the case that you want to stop briefly after each animation just try Rick's suggestion.

RickJ

Gilbot: Thanks for the correction.  I totally missed the blocking argument.   He can still try using the Wait()s for testing purposes to see what is actually happening.

poc301: Gilbot is right.  The blocking argument to the Animate...() function returns control to the engine so tha animation can be run.  When the animation is complete the script continues it's execution. 
 

poc301

Thats not the problem though.

The scrips runs fine if I remove the Wait commands, or the section of AnimateCharacterEx that tells it to wait.

If I tell it to wait until the animation finishes, the game hangs and sits there like the animation is still going on forever, even though no animation is happening.

fred

Could it be that the GlobalInts are only updated at the end of a complete game-loop? I think I've encountered a similar problem once, and it was fixed by adding Wait(1); at the end of the function in order to update all globals.

Another thing is that your function doesn't seem to have any exits - maybe you just simplified it in your post, but it would need to check for EGO's or ENEMY's hitpoints going below zero in order to conclude battle.

Can I ask how you switch turns between player and opponent? Is it done from repeatedly_execute() or another custom function with a while loop, say:

while ((character_hps > 0) && (enemy_hps > 0))
{player_attack();}

I'm asking because in a script that hangs like you describe it, you should generally track through all the loop's while-statements. The bug is probably a while-loop without exits somewhere, the probable reason you aren't getting the "15001 iterations without an update"-error is that the repeated animations takes time to execute and you exit with Alt+x before you get the message.

poc301

I really don't know...  I'm using functions to call the turns.  Here is the COMPLETE script posting (I did simplify it in the earlier post).  I have since cut the script down to bare essentials trying to fix whatever issue is causing this.  In the GUI there are 3 commands, Attack, Defend, and Special.  They are useless as of the current fight code because I wanted to simplify it until I got the problem resolved.  Anyways, here is the code :


GUI 8 (The battle GUI)
-------------------------------

if (interface == GUI8){

  if (button==1){      //DEFEND
    SetGlobalInt(9,1);    //Tells the battle script that we're defending
    heroturn();
}


  else if (button==2){      //ATTACK
    SetGlobalInt(9, 2);     //Tells the battle script we're attacking
    heroturn();
}
 
  else if (button==3){      //SPECIAL ATTACK
    SetGlobalInt(9, 3);     //Tells the battle script special attack
    heroturn();
}

  else if (button==4){      //ATTACK ? BUTTON
    Display("The Attack button will use your default attack moves against your enemy.");
}
 
  else if (button==5){      //DEFEND ? BUTTON
  Display("The Defend button will make you lose your attack, but on the next enemy attack you will take less damage, and have the chance of causing damage to the enemy with a counterattack.");
}

else if (button==6){      //SPECIAL ? BUTTON
  Display("The Special Attack button will launch a specialty attack against your enemy.  This does more damage, but can not be used as frequently as it takes time to recharge.");
}
}

So as you can see in the code above, the GUI passes a value of 1,2, or 3 to GlobalInt 9, and then calls function heroturn() at the top of the Global Script.


ACTUAL BATTLE SCRIPT BELOW (THE TOP OF GLOBAL SCRIPT):
-----------------------------------------
function enemyturn(){

int mob;
int mobhp;
int damage;
int egohp;

mobhp=GetGlobalInt(13);

if (mobhp<1){
Display("YOU WIN!");
QuitGame(1);

}

else if (mobhp>0){

AnimateCharacter(9,12,3,0);
while (character[9].animating != 0) {     //Monster attack animation
  Wait(1);
}

damage=Random(4);

}

egohp=(GetGlobalInt(14));
DisplaySpeech(0, "-%d", damage);
egohp=(egohp-damage);
SetGlobalInt(14, egohp);


if (egohp<1){
Display("You lose!"); 
QuitGame(1);
}

}


function heroturn() {
int mobhp;
int dmg;

mobhp=(GetGlobalInt(13));
dmg=Random(10);

AnimateCharacter(EGO, 8, 3, 0);           //KICK
while (character[EGO].animating != 0) {
  Wait(1);
}

DisplaySpeech(9, "-%d", dmg);

mobhp=(mobhp-dmg);
SetGlobalInt(18, mobhp);
enemyturn();

}


So as you can see, the GUI script calls the HEROTURN.  The heroturn runs, and calls enemyturn.  Once enemyturn finishes, the control is passed back to the GUI script, where the player can choose what to do next. 

However, whenever the Wait command gets run, the game sits there and does nothing until I Alt X out. 

Again, if I remove all wait commands and let the animations run quickly back to back (which is useless because you can't see anything), the script works fine.

Help!


poc301

I have also found that if I take that animation set and move it out of the function and just execute it from a normal game room, it all works fine.Ã,  The animations work and the wait until it finishes works fine.Ã, 

Could it be something with being in the function that is causing the problem?




EDIT - SOLVED:

It turns out the GUI being open was killing the animation...  On a whim due to lack of anything else to try, I disabled the GUI that was up, and it went fine.  Blech...  Ah well, thanks for all the suggestions guys.


SMF spam blocked by CleanTalk