Ahmet's Fight Game Implementation

Started by vjamesv, Sun 21/01/2007 22:58:06

Previous topic - Next topic

vjamesv

All right, well the last thing I am adding to my game is a fight scene, and I would like to use Ahmet's since that seems to fit my purposes pretty well. 

I started by copying his scripts to their respective parts into my game, and as soon as i tried saving i started running into problems.  if i added just one line of his code my game would no longer save.  i realize that this is because it was written for an older version of AGS i believe.  so i unchecked "Enforce object-based scripting" and "Enforce new-style Strings" and my game is now able to save just fine.  So my question right now is if that is okay to do? Will that mess up any other part of my game that I have been working on?


Ashen

You know, the announcement thread for a module might be a better place to post this type of question. Generally, if you post there, it's more likely people reading it will know the module/plugin/tutorial you're talking about and be able to help you.

That said in this case there's a fairly easy answer: No, unchecking those won't effect anything you might already have written. All they do (as you might be able to guess from their names) is allow compatability with older code (allowing strings instead of Strings, and functions that've been made obsolete like AnimateCharacter). They don't disallow the new versions, they just stop the old ones from crashing.
I know what you're thinking ... Don't think that.

vjamesv

Thank you for the quick reply, Ashen.  The reason I posted this here is because I figured I will have more questions as I am working on this, and I thought it would be better to have it all in one place.  Is that a good idea, or should I make separate threads for each problem?

Ashen

If they're all about Fight Game component, ask 'em here since you've started it. (I hesitate to suggest you should PM Gord10 directly, as he'll probably read them here like everyone else.)

If they're about other things, start other threads - if, and only if, you've exhausted the manual, BFAQ and forums (if there's a similar, recent thread use that), and can't figure it out for yourself. Remember to mention what you've tried and what problems/error messages you get.
I know what you're thinking ... Don't think that.

vjamesv

I am using the Keyboard Movement module in my game.  Is that going to affect using this fight game?  i noticed after putting all the code in for Ahmet's fight game my game crashed when i used the arrow keys.  i commented them out so that my game still works.  What would be the best workaround for this?

should i use different keys than arrow keys for the fight, like A, S, D, W?  i think that would still crash the game if you hit those keys while playing the game.  the reason it crashes is because the character that is controlled is not in the same room meaning the fighting characters are in the fighting room, so when you press the keys before the fight, the game crashes.

or is there a way so that those keys will only work once the fight starts?

Thank you

Oh, and here is the relevant part of the code so i don't get yelled at:

#sectionstart on_key_press 


    if ((keycode==375) && (GetGlobalInt(204)==0)) {
//    MoveCharacterStraight(AAF,character[AAF].x-10,character[AAF].y);
while (character[AAF].walking) Wait(1);
     }
if ((keycode==377) && (GetGlobalInt(204)==0) && (character[AAF].x<230)){
//    MoveCharacterStraight(AAF,character[AAF].x+10,character[AAF].y);
while (character[AAF].walking) Wait(1);
     }
if ((keycode==372) && (GetGlobalInt(204)==0)) {
//    MoveCharacterPath(AAF,character[AAF].x,character[AAF].y-30);
//    MoveCharacterPath(AAF,character[AAF].x,character[AAF].y);
while (character[AAF].walking) Wait(1);
     }

Ashen

The obvious solutions are to add a check that the character is in the same room as the player (if (cAaf.Room == player.Room)) or use a variable to check if the fight has started (which you kind of suggested yourself). Use a custom int or a GlobalInt.

On a maybe-related note - what does the GetGlobalInt(204) == 0 part of the conditions check for? You could possibly use that, instead of adding another check (just don't have it set to 0 before or after the Fight).
I know what you're thinking ... Don't think that.

vjamesv

#6
Thanks again for the quick reply.  I am not sure what the globalint(204) checks for so i will use a different one so i don't mess up another part of the code. 


EDIT:
------
all right, i checked the global script, and 204 is used for defense mode so i won't use that one:

SetGlobalInt(204,0);//Defence

vjamesv

Hey, setting the global integer worked great!  i am amazed at how well the fight is working already.  i am trying to use my own animations so that is making it a bit complicated, but everything is working so far. 

when you enter the room to fight, the key codes work now so you can move and you can punch and kick.  now as i was moving around the game crashed, and here was error message:

---------------------------
Adventure Game Studio
---------------------------
An error has occured. Please contact the game author for support, as this
is likely to be a scripting error and not a bug in AGS.
(ACI version 2.72.920)

in Room 37 script (line 286)

Error: SetLabelColor: specified control is not a label

---------------------------
OK   
---------------------------

and here is the room script:


function room_g() {
  // script for room: Repeatedly execute
if ((GetGlobalInt(200)<=20) && (GetGlobalInt(200)>10)) {
SetLabelColor(3,1,54848); 
SetLabelColor(3,2,54848);         //////////////////////Line 286
}
if (GetGlobalInt(200)<10) {
SetLabelColor(3,1,63808); 
SetLabelColor(3,2,63808); 
}

this happened a few times with different lines causing the problem, but it was the same type of code.  i am not sure what setlabelcolor even does, so i will look around for that, but does anyone have an idea on how to fix that?

I also got an error, unfortunately i did not save it, and i have not been able to repeat it, but it basically was saying it could not move an object to a certain position and crashed.  i think this is because my resolution is set at 320x200, and i think ahmet's game is slightly bigger since when i use his graphics the characters head is not on the screen.  here is the part of the code that caused that error:

if(IsTimerExpired(4)==1) {
  SetTimer(4,160);
   if (GetGlobalInt(205)>=7){
  DisplaySpeechBackground(GGF,"Aduket!");
  SetGlobalInt(205,0);
  SetObjectPosition(3,character[GGF].x-30,100);      ///////this line caused the error
  AnimateCharacter(GGF,11,10,0);
  ObjectOn(3);
  MoveObject(3,character[AAF].x,100,7);
  while (IsObjectMoving(3)==1) Wait(1);
  SetGlobalInt(200,GetGlobalInt(200)-3);
  MoveCharacterDirect(AAF,character[AAF].x-20,character[AAF].y);
  while (character[AAF].walking ==1) Wait(1); 
  ObjectOff(3);
  if(character[GGF].x<290) MoveCharacter(GGF,character[GGF].x+5,200);
    }
}

Can someone please help me try to figure out how to get that one working?  Thanks a ton!  This is the last part of my game to do, so once this is done i will be putting up a full demo.

Khris

I don't want to be offensive, but do you try to fix those errors by yourself at all?

SetLabelColor(3,2,54848); crashed the game, and the error message even stated the exact cause of the problem.

Check GUI object 2 on GUI 3, it's obviously no label but something else.
From the look of the code, this is supposed to be some sort of health bar or something similar, so look through the module's GUIs and adjust the 3 (the 2 is probably correct, but 3 is the wrong GUI) in every SetLabelColor-line, of course.)

Ashen

If you added this after you added the SaveLoad GUI stuff, Khris's suggestion is almost certainly correct. (You'll have at least 3 more GUIs that Ahmet's code anticipates.) While I realise this is a little hard to look up in the manual (SetLabelColor being obsolete), it shouldn't have been too hard to solve with some thought.

I'm not sure what the problem with the SetObjectPosition command would be. I'm not sure the resolution can be the issue since, AFAIK, Object positions aren't bounded by the Screen coords (the major difference between resolutions) and can be negative values (setting its position to be off screen, or even outside the ROOM coords should be a problem). Since you've not been able to repeat it, I guess it goes on the 'Odd, but no big deal' pile. If you do get the error again, make sure to copy the exact wording.
I know what you're thinking ... Don't think that.

vjamesv

You guys are hilarious.  I love this message board. 

I just commented out all the set label stuff since i don't think it is necessary to have the hit points displayed. 

the setobject position was because the enemy could throw a fireball at you, and so i commented that out too because i don't think i am going to use fireballs... 

so i am busy plugging away trying to get all the animations working and it is going smoothly so far.  thanks for all your help!

vjamesv

All right the fight works pretty nicely for me for me so far.  I just have one thing i would like to try to figure out.

Once in a while my character seems to teleport, but i have a hard time figuring out what is causing this.  it seems to be when i am defending and trying to move that he will jump, but i have seen him teleport to the other side of the screen twice, i just can't seem to get him to do it again.  anyone know what might cause this?

you can download my game here:

http://www.deercrack.com/banana/games/bmtvg/Banana%20Man.zip

and i have left debug mode on, so you can teleport to the fight by hitting control x and then entering in room number 37.

And here is the code for movement:
(GlobalInt 204 is for defense mode, and GlobalInt 206 is an integer i used so that the keys only work on the fight screen and not the rest of the game)

    if ((keycode==375) && (GetGlobalInt(204)==0) && (GetGlobalInt(206)==1)) {
    MoveCharacterStraight(AAF,character[AAF].x-10,character[AAF].y);
while (character[AAF].walking) Wait(1);
     }
if ((keycode==377) && (GetGlobalInt(204)==0) && (character[AAF].x<230) && (GetGlobalInt(206)==1)){
    MoveCharacterStraight(AAF,character[AAF].x+10,character[AAF].y);
while (character[AAF].walking) Wait(1);
     }
if ((keycode==372) && (GetGlobalInt(204)==0) && (GetGlobalInt(206)==1)) {
    MoveCharacterPath(AAF,character[AAF].x,character[AAF].y-30);
   
    AnimateCharacter(AAF,11,0,10);
   
    MoveCharacterPath(AAF,character[AAF].x,character[AAF].y);
while (character[AAF].walking) Wait(1);
     }

  if ((keycode==67) && (GetGlobalInt(206)==1)) {
      SetGlobalInt(204,1);
      ChangeCharacterView(AAF,55);
               }
  if ((keycode==86) && (GetGlobalInt(206)==1)) {
      SetGlobalInt(204,0);   
      ChangeCharacterView(AAF,53);
            }       
   //Block

  if ((keycode==90) && (GetGlobalInt(204)==0) && (GetGlobalInt(206)==1)) { //Kick
AnimateCharacter(AAF,8,10,10);

PlaySound(46);

Wait(30);
AnimateCharacter(AAF,0,10,10);

if (character[AAF].x+40 <character[GGF].x) SetGlobalInt(205,GetGlobalInt(205)+1);
     if (character[AAF].x+60 >=character[GGF].x) {
    MoveCharacterStraight(GGF,character[GGF].x+10,character[AAF].y);
    SetGlobalInt(201,GetGlobalInt(201)-1);
//    PlaySound(51);
    MoveCharacterStraight(AAF,character[AAF].x-3,character[AAF].y);
}
if ((character[AAF].x+40<character[GGF].x) && (character[AAF].x+60 >=character[GGF].x)) {
    MoveCharacterStraight(GGF,character[GGF].x+4,character[GGF].y);
    }
      }
//     if (GetGlobalInt(202) - GetGlobalInt(203) <= 30) SetGlobalInt(201,GetGlobalInt(201)-1);
// }
if ((keycode==88) && (GetGlobalInt(204)==0) && (GetGlobalInt(206)==1)) {//Punch
AnimateCharacter(AAF,9,10,10);

PlaySound(45);

Wait(30);
AnimateCharacter(AAF,0,10,10);

if (character[AAF].x+60 <character[GGF].x) SetGlobalInt(205,GetGlobalInt(205)+1);
     if (character[AAF].x+40 >=character[GGF].x) {
   MoveCharacterStraight(GGF,character[GGF].x+10,character[AAF].y);
    SetGlobalInt(201,GetGlobalInt(201)-1);
    MoveCharacterStraight(AAF,character[AAF].x-3,character[AAF].y);
//    PlaySound(51);
  }
  if ((character[AAF].x+40<character[GGF].x) && (character[AAF].x+60 >=character[GGF].x)) {
    MoveCharacterStraight(GGF,character[GGF].x+4,character[GGF].y);
    }
}
   if ((keycode==380) && (GetGlobalInt(206)==1)) {
// AnimateCharacter(AAF,10,10,0);
}
}


SMF spam blocked by CleanTalk