[SOLVED] Do I have this set up right to be called in AGS?

Started by Icey, Sun 20/05/2012 21:43:29

Previous topic - Next topic

Icey

Do I have this set up right to be called in AGS?

Code: ags


import void gainExperience(int amount)
{
    playerXP += amount;
    if (playerXP >= BaseEXP)
    {
        levelUp();
    }
}

function levelUp()
{
	DisplayAt(115, 10, 200, "Dave Leveled up!");
    BaseEXP += 100;
    playerHP += 10;
		playerMP += 8;
		PlayerBaseHp = playerHP;
		PlayerBaseMp = playerHP;
		if(PlayerBaseHp >= FinalHP){//DAVE [HP]: 10000. DAVE [HP]: 9999//
    PlayerBaseHp = FinalHP;
  }
  if(PlayerBaseMp >= FinalMP){
    PlayerBaseMp = FinalMP;
  }
		
		
}


Well what I really want to know is should I use the import void thingies? I never really used them so I don't know much about them. This is all placed in a different script btw.

monkey0506

import is used to make a function/variable global. So if you don't need to call the gainExperience function from other scripts, then you don't need import at all.

Presumably, you are going to need to call it from other scripts though, so in the header (the ASH file, not ASC) you can put the import:

Code: ags
import void gainExperience(int amount);


The function itself is defined in the script file (ASC), just like you have it, but without the "import".

void is the return type. That just means that you don't need the function to return any data back to wherever you're calling the function from. If you needed to return some data based on the result of the function, you could change the return type appropriately.

Oh, and you didn't really specify, but DO NOT EVER, EVER, EVER, EVER, EVER DEFINE A FUNCTION INSIDE OF A SCRIPT HEADER (*.ASH) FILE!! That's what imports are for. I just wanted to make that clear. Functions and variables should NEVER be defined in a script header. The import keyword lets you use that function/variable in other scripts.

Khris

import is used to make a function available to other scripts.

Code: ags
// header
import void gainExperience(int amount);

// script

void gainExperience(int amount)
{
  playerXP += amount;
  if (playerXP >= BaseEXP)
  {
    levelUp();
  }
}


void is an alternative to function, which is actually the same as int. Since the function doesn't return an integer value, technically, void is "most correct". But since AGS allows int/function for functions that don't return anything, you don't have to use it if the function has no return value.

Also check your indentation, you're increasing it arbitrarily in the second function.
And, shouldn't levelling up increase the base stats?

Icey

Thanks guys, I think I understand how these terms work now.

@Khris: Well the thing is I was looking for a script online that would give me a more universal leveling system and came across one that was for Unity. I noticed that it wasn't that far from AGS scripting so I just took it changed it up a lot to fit what I needed. However it is incomplete because there are stats missing such as ATk and MGK.

However I noticed a problem though with the current script.
Code: ags
    
function levelUp()
{
   DisplayAt(115, 10, 200, "Dave Leveled up!");
    BaseEXP += 100;
PlayerBaseHp = playerHP;//This is supposed to be here. This should make the current life equal the normal base
      PlayerBaseMp = playerHP;
    playerHP += 10;//gives 10points to life
      playerMP += 8;
      PlayerBaseHp = playerHP;//makes the life equal the new base
      PlayerBaseMp = playerHP;
      if(PlayerBaseHp >= FinalHP){//DAVE [HP]: 10000. DAVE [HP]: 9999//
    PlayerBaseHp = FinalHP;
  }
  if(PlayerBaseMp >= FinalMP){
    PlayerBaseMp = FinalMP;
  }

Khris

Okay, what problem?

Regarding what it does, don't copy and alter a script without really knowing what you're doing.
Judging from your comments, you're confusing the variables in your = lines.
a = b; will take the value of b and store it in a, not the other way around.

Here's what I think should happen:
Code: ags
  // increment base stats / max values
  PlayerBaseHP += 10;
  Player.BaseMP += 8;
  // fill up health and magic points
  playerHP = PlayerBaseHP;
  playerMP = PlayerBaseMP;

Icey

Ok I see now, I guess I wasn't paying attention other wise I would'a caught that. Thanks though Khris.

Khris

You HAVE to do this, don't you? "Not paying attention", yeah right. (roll)
Why not just admit that you didn't really know what you were doing, which is obvious from your code?
Or just say nothing except "thanks"? But no, you have to drop a lame excuse at the very end. Grow up, you're only fooling yourself.

monkey0506

At the sake of making your brain explode, you're updating the BaseHP to the FinalHP after setting the PlayerHP to the BaseHP which means that if BaseHP ever exceeds the FinalHP the PlayerHP isn't being updated.

Code: ags
function levelUp()
{
  DisplayAt(115, 10, 200, "Dave Leveled up!");
  BaseEXP += 100;
  PlayerBaseHp += 10;
  PlayerBaseMp += 8;
  if(PlayerBaseHp >= FinalHP) //DAVE [HP]: 10000. DAVE [HP]: 9999//
  {
    PlayerBaseHp = FinalHP;
  }
  if(PlayerBaseMp >= FinalMP)
  {
    PlayerBaseMp = FinalMP;
  }
  // false, that shouldn't have been here, it belongs up there, where it can actually do something useful.
  playerHP = PlayerBaseHp; // set the player HP to the new base HP
  playerMP = PlayerBaseMp; // you were also setting the MP to the HP...fixed that for you
} // missing bracket? found it!


I will never understand why you insist on taking the indentation (which AGS handles automatically) and raping the hell out of it. It's clear you don't have the slightest idea of what indentation is for. I'm not saying that makes you a bad person, and I don't mean it as an insult, it's just become apparent. So please, stop indenting things. It will actually make your code more readable if you just stop.

Icey

@Khris: Khris, I'm telling you the truth, in my other RPG scripts for my other games I have always have them set up right. This is my first time (1) using someone else's script (2) editing it so that it works for me. This script was not given to me by you or monkey other wise it might of looked different but still it works, it's just missing some of the things I usually put in my other scripts but it's cool. I got distracted by other things in life(mostly doing to much at once) and I wasn't paying attention to everything. It's no big thing as I would have noticed it anyways before coding the actual battle system.
:wink:

@Monkey: Well I don't really indent much. It mostly comes from copy & pasting. Which indents it on it's own(like you guys already know) but I can still understand everything my self. But I can start doing it my self more often. :)


SMF spam blocked by CleanTalk