Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - johanvepa

#161
Quote from: Crimson Wizard on Mon 06/05/2013 22:47:51
You do not declare function parameter types properly, it should be:
Code: ags

function castspell(int spellname); // I guess spellname is integer?


The parameters should be declared like:
(type name, type name, type name).


Damn, you beat me to it. And I was so happy because I saw it myself.
#162
Thank you, Crimson. These past few months have been highly educational.

EDIT: Solved it.
#163
Quote from: Crimson Wizard on Mon 06/05/2013 21:18:58
Nanuaraq, I strongly recommend you to explicitly define your function's type depending on what value you are returning. What you wrote may work with integers, but it may cause problems with other types (not sure that will compile). Also it will prevent possible confusions in the future.

What I mean: instead of "function AdjustCharacteristicForExp" write "int AdjustCharacteristicForExp". The word before function name is function return-type.
By default AGS allows to return integer if you start function declarations with just "function" but I find this pretty non-obvious. Probably it was left for backwards compatibility.

So a function can be defined as an integer? Or rather, an integer may return a value created by a function?

I'm not entirely sure what the catch is, but if I get what you're saying, a function that has "return" in it somewhere always returns something, and that something should be defined as either integer or some other thing.

By the way, what others than integers could the return-type be? I ask because I have not seen anything like this in the manual (or perhaps I didn't look thoroughly enough).

And thank you.
#164
There. I re-scripted the code for adjusting Ego's strength attribute and his skill with the spell BAKECAKE.



Code: AGS


//integers on experience demand for characteristics

int DemandForSTRENGTH;
export DemandForSTRENGTH;

int DemandForBAKECAKE;
export DemandForBAKECAKE;



//adjust characteristics for experience, with modifier for the experience demand integers (how tough it is to raise)

function AdjustCharacteristicForExp(int Characteristic,  int expCharacteristic,  int demand)
{
while (expCharacteristic >= demand)
  {
  expCharacteristic -= demand;
  if (Random(100) > Characteristic)
    {
    Characteristic ++;
    }
  }
return Characteristic;
}

//having adjusted characteristics levels,  now to do away with the spent experience
function AdjustExpAfterAdjustingCharacteristic(int expCharacteristic,  int demand)
{
while (expCharacteristic >= demand)
  {
  expCharacteristic -= demand;
  }
return expCharacteristic;
}

//Handy adjust-all when gaining experience
function AdjustAllCharacteristicsAndExp()
{
STRENGTH = AdjustCharacteristicForExp(STRENGTH,  expSTRENGTH,  DemandForSTRENGTH);
expSTRENGTH = AdjustExpAfterAdjustingCharacteristic(expSTRENGTH,  DemandForSTRENGTH);

BAKECAKE = AdjustCharacteristicForExp(BAKECAKE,  expBAKECAKE,  DemandForBAKECAKE);
expBAKECAKE = AdjustExpAfterAdjustingCharacteristic(expBAKECAKE,  DemandForBAKECAKE);


SETMAXSTATISTICS(); //function that applies the updated characteristics to the maximum health and mana integers
}

function game_start() {   

DemandForSTRENGTH = 2;
DemandForINTELLIGENCE = 2;
DemandForMAGICUSE = 2;
DemandForOPEN = 1;
}




I can report that the above works very well. Scripting the rest of the characteristics will be much more straightforward. Thank you for the pointer on using variables with my functions and the return effect.

#165
No wait, I got it now. Doing the "return"-thingamagig really changed things.

Will report back once I've had a chance to test it.
#166
I can report that the above stated works.

Comments are welcome.
#167
Quote from: Iceboty V7000a on Sun 05/05/2013 13:56:45

"The VALUE of the variable STRENGTH is passed to the function, but not the variable itself. So, the function just modifies a 'copy' of that variable it and will NOT affect the original variable. "


Now THAT explains a lot. So, the integers put in the paranthesis after the function name is acting as numbers, not affecting the integer placed there.

The  way I see the code you altered, it will return a value which I can use to alter the BAKECAKE and any other integers, using a collect-all function with this inside:

Code: AGS

BAKECAKE = adjustskillforexp(BAKECAKE, expBAKECAKE, toughness)
//and so on with all the different skills


What my function did was create a value based on the STRENGTH integer (int this case, STRENGTH + 1), but not to return anything!

Like writing "2+2" but no "=".

And therefore, my adjustallskillsforexp function should instead define that the BAKECAKE integer be set to the returned result of the function adjustskillforexp using the value of BAKECAKE as a variable.

But then again, something's amiss. I'm trying to adjust both the integer BAKECAKE and the integer expBAKECAKE at the same time here. Increasing the integer BAKECAKE must be followed by a subtraction from the integer expBAKECAKE, since I spend the experience points to attempt the chance at raising the skill. If the experience points stay where they are, I can keep on attempting to raise the stats and never spend a single exp point in doing so which could have my game in an endless loop? Or would the value of expCharacteristic still count down inside the function? Anyway, I would be "recycling" the exp points, meaning next time I check if I have enough exp points, I would still retain those from the first check.

So my function needs to return TWO values. To my knowledge, that isn't possible, yes? Since I can't tell AGS by use of a function to initiate another function using a certain integer as variable, the only way I can do what I want is this, right?:

Code: AGS


function CheckSTRENGTHGainForExp(toughness)
{
while (expSTRENGTH >= toughness)
  {
  expSTRENGTH -= toughness;
  if (Random(100) > STRENGTH)
    {
    STRENGTH += 1;
    }
  }
}

function CheckALERTNESSGainForExp(toughness)
{
while (expALERTNESS >= toughness)
  {
  expALERTNESS -= toughness;
  if (Random(100) > ALERTNESS)
    {
    ALERTNESS += 1;
    }
  }
}

function CheckBAKECAKEGainForExp(toughness)
{
while (expBAKECAKE >= toughness)
  {
  expBAKECAKE -= toughness;
  if (Random(100) > BAKECAKE)
    {
    BAKECAKE += 1;
    }
  }
}

//and so on and so forth until I'm through all of the SKILLS and expSKILLS integers I got attached to my character.

//And then, once I use my skill in casting the spell BAKECAKE, I can, having cast the spell, put this in near the end of the spellcasting function:

CheckBAKECAKEGainForExp(1); //meaning you need 1 exp point to attempt to raise the stat

//Or, I could gather them all together in this function:

function adjustallskillsforexp();
{
CheckSTRENGTHGainForExp(2);
CheckALERTNESSGainForExp(2);
CheckBAKECAKEGainForExp(1); //this spell isn't so hard to raise as the other skills.
}



And this would probably work, since the altering of the integers BAKECAKE and expBAKECAKE are not dependent upon a function returning a value, it is done directly in the function. It wouldn't look good, tough, it would be cluttered and tough to alter afterwards. But I can't see a way around it, otherwise. What do you think?

Oh, and Khris, I was sorta aware that I wasn't doing a "function within a function", since that would mean defining a function withint another function, yes? Bear with me for being imprecise, as I know you have before.
#168
I recently got an answer to this topic:

Character status screen

Well, things are going great, but I am reaching a dead end when trying to simplify some functions.

I made an experience system where, whenever you use a skill, you gain one exp. point in that particular skill. Whenever you do gain a point in a skill, it then checks with a random to see if that point gets you a raise in the skill you just used. Some skill stats are harder to raise from experience; whenever a skill is used, gain one exp., then do a check to see if three points are available.  if three points are available, do a random check to see if spending those exp points raises the stat in that skill. if three points are not available, wait until more exp points are gained in the skill.

This repeats every time the skill is used, and eventually, the skill raises. The higher the skill, though, the lower the probability that the skill is raised.


So far so good, I can get that to work.


But, then I try to make a function that collects all possible skills into one function, so I save space and avoid typing in skill raising functions for every possible skill.

In short, I do something like this:

In the global script:
Code: AGS


//skill with a certain spell, skills go from 0 to 100.
int spellBAKECAKE;
export spellBAKECAKE;

int expBAKECAKE; //experience with the same spell
export expBAKECAKE;


//here we insert the characteristics of the spell BAKECAKE into a function and add toughness for how much exp it takes to attempt to raise the stat:

function adjustskillforexp(int Characteristic, int expCharacteristic, int toughness)
{
while (expCharacteristic >= toughness)  //the higher the toughness, the more exp needed to do that random check and see if skill is raised.
  {
  expCharacteristic -= toughness; //when doing the random check, the exp is lost, regardless of the result
  if (Random(100) > Characteristic)
    {
    Characteristic += 1;  //in this case, skill raised
    }
  }
}

function adjustallskillsforexp()
{
adjustskillforexp(STRENGTH, expSTR, 2); //so STRENGTH is attempted raised whenever two exp. points in that skill are gained.
adjustskillforexp(ALERTNESS, expALE, 2);

adjustskillforexp(spellBAKECAKE, expBAKECAKE, 1); //and our spell BAKECAKE is attempted raised whenever one exp point in that skill is gained.
}




What I want to do with this is; whenever exp is gained, do the adjustallskillsforexp(), that way experience is always channeled into stats raising.


This worked until I made the two abovementioned functions. But it should work. Ought to. Really.

Can anyone see the fault?


#169
Thank you very much, both of you. Things are working out just fine here   :)

And I found the proper place in the manual, too.

Never gt around to setting integers as string and vice versa, but found out I didn't need to, as long as I stick to integers and labels in the GUI.
#170
Khris, are you some kind of wizard?

Anyway, I tried it out, and can report that it works. And thank you very much for being there to save the day. The strength score now is displayed in the lblSTRENGTH label in the character status GUI when I press the "show status screen" button in the generic status bar GUI.
(And the strength attribute working as an int may come in handy for saving little old ladies from robbers and such. )

Two questions:
Is it possible to simplify the relation between the strength value integer and the strength label further?
I am thinking something like using the label as an int rather than as a textual display of the value of an int. If I can make the lblSTRENGTH have a value in numbers, rather than being a piece of text, which I must then format to show the value of an int, I could use it as an int in and of itself. Simply put, first question: Can I use a label as an integer?


Second question, being ambitious, I decided also to have a name tag label.
In the character status screen GUI, I therefore also put a label called lblNAME.

I use this in my globalscript.asc:
Code: AGS

String NAME;
export NAME;


and this in my globalscript.ash:
Code: AGS

import String NAME;


now, at the beginning of the game, at the first room load of the first room, I put this (amongst others):
Code: AGS

NAME = Game.InputBox("So what's your name, fella?");
lblNAME.Text = NAME;


And it works! When I press the status screen button, the NAME appears at the lblNAME label. And stays there.

Now, when someone is talking to cEgo, I would like them to greet him, saying something like "Hello there Wilbur, what are you doing here in this rainy weather?". So I tried with this in the room script:

Code: AGS

Display(String.Format("have a nice day, %d", NAME));


Alas, here my luck ends. Instead of the NAME, a string of numbers is displayed.

I'm pretty certain there must be a completely straightforward solution to this??
#171
I think I got the hang of global integers now, but I need to confer upon the player the means of keeping track of certain essential values. I need a status screen, in other words, and I think I should do it as a GUI.
(not that it has to be a GUI, but I believe thats the best way to go?)

I would like to have some global variables shown in a simple manner. Nothing fancy, just like for example:

Attributes:
Strength 12
Dexterity 18
Wits 8

Status:
Health 2 / 15
Magical energy 30 / 65

Basic needs:
You are hungry
You are sleep-deprived

And perhaps a picture or two to top things off. I want to simply allow the player to push a button, which displays this GUI (and pauses the game). On clicking the GUI the game unpauses and the GUI becomes invisible again. I've tried using the standard buttons to come up with something but it seems to be harder than it, well, harder than it seems.

This should be such a simple task, yes? But I can't see the forest for the woods.
#172

And we're back on track, Wo-Hoo!

Thank you so much!
#173
I recently suffered a hardware crash, but managed to salvage the contents of the harddisk. So now I have everything in a folder and need to reinstall AGS. How to go about reinstalling when I don't even know where in the folder the source code is? I saved all my artwork, and the executable, but I need the coding back on track. How do I do that?
#174
Tested and working. Thank you very much.
#175
Forgive me if I ask a stupid question here, but shouldn't there be a couple more brackets, like this:

Code: ags
// room script, below room_Load

function on_call(int p) {
  if (p == 1) 
      {room_Load();
      }
}

// global script

  CallRoomScript(1);


???
#176
Thank you very much for your replies. I'm on to make it work.

I wonder, can I simplify the script a bit? or would that mess it up? What if I did this:

Code: AGS
    
// room script, below room_Load
     
    function on_call(1)
      {
      room_Load();
      }
     
    // global script
     
function bCamp_OnClick(GUIControl *control, MouseButton button)
{
TIME += 15000;
Display("After half an hours rest, you feel ready to move on.");
//thingamagig about restoring health values, not coded yet
CallRoomScript(1);
}


where bCamp is my "rest" button and TIME is my rep-exec timer keeping track of game time.
#177
I want to add a button that lets me re-load any room's room_Load(); script.

If I simply tell the globalscript to do the function room_Load(); whenever I press a certain button, it does not recognize the function, since the function room_Load(); is in the local room script, not the global script.

I tried this in the global script to work around it:

Code: AGS

function roomupdate();
  {
  room_Load();
  }


but it doesn't work.
#178
Thank you, that did the trick.

Quote from: Crimson Wizard on Mon 01/04/2013 01:56:42
Dialog is a global entity, not related to any room in particular. Declare variable as imported in the GlobalScript.ash instead, so that it is visible in any script.
#179
Yeah, I wanted to put the bool at the top of the room script, but since it is linked to looking at a character, and looking at a character can only be done via the globalscript.asc (right?), I had to have it in the global.

Quote from: Khris on Mon 01/04/2013 02:09:55
Also, if you're going to have a manageable number of them, I'd recommend using the Global variables pane instead.
#180
I'll try that, thank you.

Quote from: Crimson Wizard on Mon 01/04/2013 01:56:42
Quote from: Nanuaraq on Mon 01/04/2013 01:07:18
I have defined the seentattoo bool in my globalscript and exported it. I have imported it to the room where the dialog is taking place. Am I missing something here?
Dialog is a global entity, not related to any room in particular. Declare variable as imported in the GlobalScript.ash instead, so that it is visible in any script.
SMF spam blocked by CleanTalk