How do I set a number to this?[Solved]

Started by Icey, Mon 31/01/2011 22:58:22

Previous topic - Next topic

Icey

This is what I have so far.
Code: ags

   String playerHP == 100;// I get an error for this

  strengths.Text = String.Format("HP: %d", playerHP);//HP displayed in the stat menu
    pairHP.Text = String.Format("HP: %d", playerHP);HP displayed in the command menu
 String EnemyST == 50;// I get an error for this
  enemystats.Text = String.Format("HP: %d", EnemyST);enemy HP display in EnemyHP gui

After the error I took off the == & 100/50

Now I need to know if there is another way to apply the number back on there so it will show up on the GUI's labels.


UPDATE
As I was playing I noticed that the numbers do show up only they show 0.

ddq

Simply put, you're using Strings, which are for text, when you should be using int, which is for numbers.

Khris

You can't set a String to 50, 50 is an integer.
You can set a String to "50" or an int to 50.

These will work:

Code: ags
  String a = "50";
  int b = 50;


Note that you can't set Strings to initial values outside of functions.

What you'll want is this:

Code: ags
int playerHP == 100;

  strengths.Text = String.Format("HP: %d", playerHP);

Icey

Oh. Now I know to use Int's for such a thing from now on.

Thanks guy.

Icey

Oh and how do I subtract & add to the int's?


ddq

BY FUCKING RIGHT OFF

Sorry, but I don't think you can be helped. Read the manual and look up tutorials for AGS and C-like script syntax in general, as if it will do you any good.

(Free hint: use + and - for Pete's sake)

Also, for assignments, you're using == instead of = on those two lines. Only use == when you're testing to see if things are equal, not if you're telling it what to equal.

Khris

 :o

You use this:    =

On the left side you put the variable you want to set, on the right side you put a value or expression.
To add 10 to playerHP, you'd use:

Code: ags
  playerHP = playerHP + 10;     // right side is evaluated, result is set as new value of left side


There's also the short version:

Code: ags
 playerHP += 10;    // add 10 to value of playerHP


I'm almost afraid to ask, but how on earth did you handle that in the past; how did all your PMQ games keep track of the player's health?

DoorKnobHandle

Quote from: Khris on Mon 31/01/2011 23:17:12
I'm almost afraid to ask, but how on earth did you handle that in the past; how did all your PMQ games keep track of the player's health?

I'm pretty sure he made a million of these annoying, stupid and pointless threads until people gave him code he was able to copy&paste successfully.

Icey

#8
I was never able to the RPG style in my PMQ games even though I ask how here and there. I was never even half way smart with AGS. But I noticed that I need to use only one =.

You know I am not a advance AGSer or even half way close I am still a n00b in many areas because I dont try to leave my small box of AGS knowledge but when I do I find my self learn more & more about AGS but I still get stuck here & there like any other user.

I did not say that to sound upset about anything I just wanted to point out something that I had on my mind for quite some time now. :-\

Icey

#9
This is what I have so far

Code: ags


function bomb1_UseInv()
{
//--------Trick E part----------------------------------------//
  if(p1.NormalGraphic == 168){
  if(Dave.ActiveInventory == com1){//Attack
    Dave.ChangeView(18);
    Dave.Animate(2, 4, eOnce, eBlock, eForwards);
   
   EnemyST -= 5;
   
  }
  
  
  
   //Enemy lose HP(place here)
 }
  if(p1.NormalGraphic == 171){
     if(chris.ActiveInventory == com3){//Draw
    chris.ChangeView(17);
    chris.Animate(2, 5, eOnce, eBlock, eForwards);
    muffy.AddInventory(com4);
  }
    //Enemy lose HP(place here)
 }
  if(p1.NormalGraphic == 170){
    if(muffy.ActiveInventory == com4){//magic
    muffy.ChangeView(18);
    muffy.Animate(2, 4, eOnce, eBlock, eForwards);
    EnemyST -= 3;
  }
    if(muffy.ActiveInventory == com5){//magic
    muffy.ChangeView(18);
    muffy.Animate(2, 4, eOnce, eBlock, eForwards);
    EnemyST -= 3;
  }
    if(muffy.ActiveInventory == com6){//magic
    muffy.ChangeView(18);
    muffy.Animate(2, 4, eOnce, eBlock, eForwards);
    EnemyST -= 3;
  }
  
  
  
   //Enemy lose HP(place here)
 }
  if(p1.NormalGraphic == 169){
     if(tifa.ActiveInventory == com2){
    tifa.ChangeView(16);
    tifa.Animate(2, 4, eOnce, eBlock, eForwards);
    playerHP += 7; 
  }
    
 }
 //Break check
if(EnemyST == 0){
  bomb1.TweenTransparency(1.0, 100);
  //Play death sound
  GiveScore(10
  bomb1.Visible = false;
  HUD.TweenTransparency(0.5, 100);
  HUD.Visible = false;
}

//If enemy is still alive continue on below
//enemy animate (place here) **[NOTE:Make animation for enemy 1/31]**
playerHP -= 10//player lose HP (Place here)
if(playerHP == 0){
  //add death info for player
}
//<Life or death> (2)If plaer is alive continue on below
//----------------------------------------------------------
 if (player2.NormalGraphic == 10){
  //commands.CharacterToUse = Dave;
  //Dave.SetAsPlayer();
     Dave.ChangeView(18);
    Dave.Animate(2, 4, eOnce, eBlock, eForwards);
  EnemyST -= 5;
}
 if (player2.NormalGraphic == 45){
// commands.CharacterToUse = chris;
// chris.SetAsPlayer();
   chris.ChangeView(17);
    chris.Animate(2, 5, eOnce, eBlock, eForwards);
  muffy.AddInventory(com4);
}

 if (player2.NormalGraphic == 73){
  // commands.CharacterToUse = muffy;
   //muffy.SetAsPlayer();
    muffy.ChangeView(18);
    muffy.Animate(2, 4, eOnce, eBlock, eForwards);
    EnemyST -= 3;
}

 if (player2.NormalGraphic == 63){
 // commands.CharacterToUse = tifa;
  //tifa.SetAsPlayer();
  tifa.ChangeView(16);
    tifa.Animate(2, 4, eOnce, eBlock, eForwards);
  playerHP += 7;
}


//


}


I keep getting and error saying EnemyST/playerHP are Undefined token's

Khris

You need to make playerHP a global variable.
That's what the Global variables pane is for.


(NOTE: What follows is a long demotivational text about how to code a battle engine in general, containing the recommendation to drop creating RPGs for now.)

Also look at all that duplicate code in there.
Seriously, you need to stop coding like that.
It's no wonder your games are chock-full of bugs.

You have to learn how to code things properly, otherwise you are on your own. I won't write a battle engine for you; and with your way of approaching coding problems, nobody else is going to help you either.

The basic idea about writing a battle engine is this:

-- isolate every piece of data that differs between player characters (and enemies). Sprites, moves, stats, equipment.

-- come up with a way to store it in a convenient, generic way. That's what structs are used for.
In essence you're creating a virtual excel sheet that lists all the specifics, e.g. max HP, current HP, standard attack view/loop, etc.
I posted my fighter struct as a pointer on how this can be done.

-- code a function that will make fighter1 attack fighter2, regardless of who fighter1 is, i.e. the party's 1st or 2nd or 3rd guy or any one of the enemies.
The function will read all the necessary values off the structs and handle the move.
As an example, here's a few lines of what function might look like:

f[] is an array of structs holding the data of the players and enemies partaking in the current battle.

Code: ags
  int attack = f[fighter1].base_attack;  // set base attack

  InventoryItem*weapon = f[fighter1].weapon;   // get inventory item set as weapon
  if (weapon != null) attack += weapon.GetProperty("attack value");  // add weapon's attack value to base attack
  
  int rr = Random(40) + 80;  // randomize value, rr is 80 to 120
  attack = (attack*rr)/100;  // attack is now 80% to 120% of its original value

  Character*attacker = f[fighter1].ch;  // get AGS character associated with fighter 1
  Character*defender = f[fighter2].ch;

  // calculate position attacker is going to move to to attack
  int to_x;
  if (attacker.x < defender.x) to_x = defender.x - 20;
  else to_x = defender.x + 20;

  attacker.Walk(to_x, defender.y);  // make attacker approach defender
  attacker.Animate(4, 3);  // play attack animation

  attack -= f[fighter2].Armor();  // decrease attack by defender's armor value
  if (attack < 0) attack = 0;
  f[fighter2].current_HP -= attack;
  if (f[fighter2].current_HP <= 0) f[fighter2].Die(); // kill fighter

  CheckDead();  // custom function that checks if all enemies or all party members are dead

  ...


[Read that and try to understand what each line does. Needless to say, this won't work on its own at all. That you were even asking when I last posted snippets clearly showed you didn't understand the code at all. That's incidentally kind of the point I'm trying to make here. If you don't understand this code, drop creating an RPG with AGS until you learned how to program shit. Seriously.
The above code is pretty much (part of!) the absolute minimum of what's required, it doesn't contain fancy stuff at all.]

-- code a main battle loop that waits for player input, determines the order in which party members and enemies attack, calls the attack function, cleans up, etc.


Just imagine for a second you decided that at some point, somebody else is going to join the party. You'd have to rewrite every single enemy's UseInv function in every single battle in the entire game.
This is NOT how shit is done.

monkey0506

#11
I know Khris has posted his huge post before I'm even starting to type mine..but I'm gonna say this anyway.

If you're getting errors about something being an undefined token that means that whatever word you are using in the script is not defined. The AGS script does not understand what playerHP or EnemyST mean until you define them. Presumably they are simple integer variables. But until you tell AGS what they are..they don't mean anything.

It's like if I started just gheahe new words without ahedhfg you what they rhogowq.

Make sense?

If you're defining variables directly in the script and you want to use them in another script, you have to import and export them. Those are both keywords that you can look up in the manual. Alternately, to make it simpler on yourself, you can, as Khris said, use the Global Variables pane instead of defining your variables in the script.

Though realistically if you're making an RPG you're going to need to set up some form of structured variable system (whether actually using a struct or possibly several dynamic arrays with accessor functions or what have you)..which would require you to have an understanding of how importing and exporting works.

And seriously..look at the scripting tutorial in the manual. You need it.

Edit: Read Khris' post now. It made me laugh because it is so absolutely true. :) Thank you Khris. We may not always see eye-to-eye on everything..but you are so completely right on this.

Icey

Ok I understand I will look at the tutorial.

But I have a conclusion question. I'm higly sure this is the last I have of this battle system. (Last time I work with the CATB system. It's just to complicated right now :(

Fisrts I had this:
Code: ags

 if( EnemyST == 0){

room18.asc(319): Error (line 319): undefined symbol 'EnemyST'

Then I Fixed it with this:
Code: ags

if(int EnemyST =< 0){

room18.asc(319): Error (line 319): Parse error in expr near 'int'

Now I know it's probably something simple but I figure it out in fact I dont even know what to look for.




Khris

You got the order wrong.
First, look at the tutorial.
Then come back here asking questions.

http://www.adventuregamestudio.co.uk/actutor.htm

Btw, what is CATB?

monkey0506

You do not utilize a variable's type in any way when accessing its value, only when defining a variable.

You can't define a variable inside of an expression.

The default value of an integer, when it is defined, is 0.

There's a number of problems with what you're doing.

Icey

O-k...

& CATB stands for Cross assault time battle. This means a battle that consist of a pair going into battle.
                                 

Matti

Quote from: Studio3 on Tue 01/02/2011 01:55:21
CATB stands for Cross assault time battle.                              

That sounds like friggin' awesome action!

monkey0506

#17
Quote from: Matti on Tue 01/02/2011 02:01:19
Quote from: Studio3 on Tue 01/02/2011 01:55:21
CATB stands for Cross assault time battle.                              

That sounds like friggin' awesome action!

I knew this was gonna be the single greatest game ever made of all time ever with absolutely no flaws or bugs or bad quality in any respect! That's clearly what CATB means!!

Cross Assault Time Battle..FTW!!

Wait, I forgot..how to post to AGS forums. Wait, I forgot..how to internet? Wiat, foehget haw 2 type lulz!

Okay..that might be just a bit on the cruel side now..

..but seriously.

Icey

Humm...

You know after looking in the link I found that most of be questions are answered there

I really should get face plumed for that. But I remember what happen last time so I am just going to keep looking through the link.

Matti

Quote from: monkey_05_06 on Tue 01/02/2011 02:06:10
Cross Assault Time Battle..FTW!!

Will there be an OSD:CATB ? I'm all for it.

Quote..but seriously.

I'm thinking of making a game: Cross Assault Time Battle: Genghis Khan's Army Vs. The Time-Travelling Bolshevik (CATB:GKAVTTTB).. or something like that.

SMF spam blocked by CleanTalk