Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: on Mon 20/08/2012 03:31:19

Title: fighting game source code
Post by: on Mon 20/08/2012 03:31:19
Hey about this code

Code (AGS) Select
if ((character[EGO].x < character[ENE].x) && (IsTimerExpired(1)==1)){
  int ran=Random(3);
  if (ran==0) {
  MoveCharacterStraight(ENE,character[ENE].x-30,character[ENE].y);
  SetTimer(1,10);
  }
  if (ran==1) {
  MoveCharacterStraight(ENE,character[ENE].x-10,character[ENE].y);
  SetTimer(1,10);
  }
  if (ran==2) {
  MoveCharacterStraight(ENE,character[ENE].x+30,character[ENE].y);
  SetTimer(1,10);
  }
  if (ran==3) {
  MoveCharacterStraight(ENE,character[ENE].x-10,character[ENE].y);
  SetTimer(1,10);
  }
}
 
if (character[ENE].x>270) {
  MoveCharacterStraight(ENE,character[ENE].x-20,character[ENE].y);
    }
if (character[EGO].x>290) {
  MoveCharacterStraight(EGO,character[EGO].x-20,character[ENE].y);
    }

if (character[EGO].x<30) {
  MoveCharacterStraight(EGO,character[EGO].x+20,character[ENE].y);
    }

witch function should i run it in?
Title: Re: fighting game source code
Post by: 2ma2 on Mon 20/08/2012 09:13:47
It's been quite some time since I worked with AGS so I'll not dwell into specific functions but rather the overall train of thought when scripting.

It mostly depends on what you wish to accomplish with it. What character is ENE for instance? EGO usually represents the player character, and the functions seem to make ENE change it's position on screen relative to the position of EGO. Since there's a timer as well, it ought to be executed repeatedly. There is such a function in the global script. Everything placed inside it will run as long as other criteria is fulfilled. But that also means that it'll execute roughly a hundred or thousand times each second (can't remember). The timer makes sure it'll execute on a more reasonable interval.

There is also three if-statements in the bottom, which makes sure that if ENE or EGO is close to the edges of the screen, it'll force it to move inwards. These are NOT limited by a timer, and thus will execute instantly. Well seemingly instantly anyway. Also, it seems that whoever wrote the script did not take into account of X of ENE is close to zero. Perhaps it's impossible for that to occur by other reasons.
Title: Re: fighting game source code
Post by: Crimson Wizard on Mon 20/08/2012 09:23:17
ig299, no offense, but I'd recommend you to first study how scripts work in AGS in general before asking such question.
Secondly, try to understand what this code is supposed to do.
Then, there's a chance you will know where to put it without our help. Or maybe you'll write your own, even better code.
BTW is it your code? Sorry if it is and I am mistaken.
Title: Re: fighting game source code
Post by: on Mon 20/08/2012 20:17:20
No it's not my code i'm just using all the help  can get so instead of starting a new threat i just copy pasted it.