(SOLVED) Custom Character Variables

Started by Creator, Fri 18/06/2010 12:07:23

Previous topic - Next topic

Creator

I want to make my character have a boolean called IsInventoryFull (as I want him to only carry one item), and I want to be able to use it like this.

Code: ags

player.IsInventoryFull = false;

if (player.IsInventoryFull == true)
{
  //do stuff...
}


I tried (in the GlobalScript header)
Code: ags

bool IsInventoryFull(Character*);


But it expects curley braces. How do I do it?

Crimson Wizard

You cannot add variables to existing classes and structs; what you can is:

a) create a custom struct, extending existing class/struct with new variables and methods; but that is not usable in your case.
b) add extender functions to existing class/struct.

I believe you already tried this, but made a mistake in function declaration.
Instead of
Code: ags

bool IsInventoryFull(Character*);

write:
Code: ags

bool IsInventoryFull(this Character*)
{
    // do inventory check and return true or false
}


Creator

#2
I knew about extender functions, but I didn't know you couldn't do the same for variables (I thought you could do something like "extender variables" I guess :P). Thanks Crimson.

SMF spam blocked by CleanTalk