Attribute in another attribute

Started by GoodGuy, Thu 29/06/2017 09:51:19

Previous topic - Next topic

GoodGuy

Hi. I have a header
Code: ags
struct GlobalTime {
writeprotected int second;
writeprotected int minute;
import attribute int Second;
import attribute int Minute;
}

a script
Code: ags
int get_Second(this GlobalTime*) 
{
  return this.second;
}
int get_Minute(this GlobalTime*) 
{
  return this.minute;
}
void set_Second(this GlobalTime*, int second) 
{
  while (second >=60)
    {
      second-=60;
      this.set_Minute(this.get_Minute() + 1); 
//Game don't allow to use attribute in script where I do a attribute definition, but this line do a error
//'.set_Minute' is not a public member of 'GlobalTime'. Are you sure you spelt it correctly (remember, capital letters are important)?

    }    
  this.second = second;
}
void set_Minute(this GlobalTime*,  int minute) 
{
  while (minute >=60)
    {
      minute-=60;
    }
  this.minute = minute;
}

monkey0506

#1
You just need to move the definition of the set_Minute extender method to be above the definition of set_Second. AGS can't call functions that have been imported (declared) but not yet defined (:~().

P.S. writeprotected members are public (for reading, not setting, obviously). You probably don't want to expose the same member in two different ways. Either use a writeprotected member with a SetMember public function OR make the member protected instead.

GoodGuy

Quote from: monkey0506 on Thu 29/06/2017 10:17:45
You just need to move the definition of the set_Minute extender method to be above the definition of set_Second. AGS can't call functions that have been imported (declared) but not yet defined (:~().

P.S. writeprotected members are public (for reading, not setting, obviously). You probably don't want to expose the same member in two different ways. Either use a writeprotected member with a SetMember public function OR make the member protected instead.
Thanks, it is work.

SMF spam blocked by CleanTalk