Game authors and players, please read this thread!

Author Topic: [SOLVED] Do I have this set up right to be called in AGS?  (Read 438 times)  Share 

icey games

  • Official KH tester
    • I can help with backgrounds
    •  
    • I can help with characters
    •  
    • I can help with play testing
    •  
    • I can help with story design
    •  
    • I can help with voice acting
    •  
Do I have this set up right to be called in AGS?

[code]

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;
  }
      
      
}
[/code]

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.
« Last Edit: 21 May 2012, 04:08 by Pub master »

monkey_05_06

  • AGS Project Admins
  • Has left the building.
Re: Do I have this set up right to be called in AGS?
« Reply #1 on: 20 May 2012, 22:00 »
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: Adventure Game Studio
  1. 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.
Let's be honest. Most people suck at coding. I suck at coding, but at least my code is readable. To Hell with anyone too lazy to maintain consistent formatting in their code. I could deal with bad interfaces and structure if I could even read your horrible code. And that's putting it nicely. -monkey

Khris

  • Evil Dark Emperor Death-Kill
    • Lifetime Achievement Award Winner
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
Re: Do I have this set up right to be called in AGS?
« Reply #2 on: 20 May 2012, 22:03 »
import is used to make a function available to other scripts.

Code: Adventure Game Studio
  1. // header
  2. import void gainExperience(int amount);
  3.  
  4. // script
  5.  
  6. void gainExperience(int amount)
  7. {
  8.   playerXP += amount;
  9.   if (playerXP >= BaseEXP)
  10.   {
  11.     levelUp();
  12.   }
  13. }

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?
http://whathaveyoutried.com/

The other day on yahoo answers:
"Can you print colored images with black ink? If so tell me how please Thanx Kimberly"

icey games

  • Official KH tester
    • I can help with backgrounds
    •  
    • I can help with characters
    •  
    • I can help with play testing
    •  
    • I can help with story design
    •  
    • I can help with voice acting
    •  
Re: Do I have this set up right to be called in AGS?
« Reply #3 on: 20 May 2012, 23:02 »
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: Adventure Game Studio
  1.    
  2. function levelUp()
  3. {
  4.    DisplayAt(115, 10, 200, "Dave Leveled up!");
  5.     BaseEXP += 100;
  6. PlayerBaseHp = playerHP;//This is supposed to be here. This should make the current life equal the normal base
  7.       PlayerBaseMp = playerHP;
  8.     playerHP += 10;//gives 10points to life
  9.       playerMP += 8;
  10.       PlayerBaseHp = playerHP;//makes the life equal the new base
  11.       PlayerBaseMp = playerHP;
  12.       if(PlayerBaseHp >= FinalHP){//DAVE [HP]: 10000. DAVE [HP]: 9999//
  13.     PlayerBaseHp = FinalHP;
  14.   }
  15.   if(PlayerBaseMp >= FinalMP){
  16.     PlayerBaseMp = FinalMP;
  17.   }
  18.  

Khris

  • Evil Dark Emperor Death-Kill
    • Lifetime Achievement Award Winner
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
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: Adventure Game Studio
  1.   // increment base stats / max values
  2.   PlayerBaseHP += 10;
  3.   Player.BaseMP += 8;
  4.   // fill up health and magic points
  5.   playerHP = PlayerBaseHP;
  6.   playerMP = PlayerBaseMP;
http://whathaveyoutried.com/

The other day on yahoo answers:
"Can you print colored images with black ink? If so tell me how please Thanx Kimberly"

icey games

  • Official KH tester
    • I can help with backgrounds
    •  
    • I can help with characters
    •  
    • I can help with play testing
    •  
    • I can help with story design
    •  
    • I can help with voice acting
    •  
Ok I see now, I guess I wasn't paying attention other wise I would'a caught that. Thanks though Khris.

Khris

  • Evil Dark Emperor Death-Kill
    • Lifetime Achievement Award Winner
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
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.
http://whathaveyoutried.com/

The other day on yahoo answers:
"Can you print colored images with black ink? If so tell me how please Thanx Kimberly"

monkey_05_06

  • AGS Project Admins
  • Has left the building.
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: Adventure Game Studio
  1. function levelUp()
  2. {
  3.   DisplayAt(115, 10, 200, "Dave Leveled up!");
  4.   BaseEXP += 100;
  5.   PlayerBaseHp += 10;
  6.   PlayerBaseMp += 8;
  7.   if(PlayerBaseHp >= FinalHP) //DAVE [HP]: 10000. DAVE [HP]: 9999//
  8.   {
  9.     PlayerBaseHp = FinalHP;
  10.   }
  11.   if(PlayerBaseMp >= FinalMP)
  12.   {
  13.     PlayerBaseMp = FinalMP;
  14.   }
  15.   // false, that shouldn't have been here, it belongs up there, where it can actually do something useful.
  16.   playerHP = PlayerBaseHp; // set the player HP to the new base HP
  17.   playerMP = PlayerBaseMp; // you were also setting the MP to the HP...fixed that for you
  18. } // 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.
Let's be honest. Most people suck at coding. I suck at coding, but at least my code is readable. To Hell with anyone too lazy to maintain consistent formatting in their code. I could deal with bad interfaces and structure if I could even read your horrible code. And that's putting it nicely. -monkey

icey games

  • Official KH tester
    • I can help with backgrounds
    •  
    • I can help with characters
    •  
    • I can help with play testing
    •  
    • I can help with story design
    •  
    • I can help with voice acting
    •  
@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. :)