Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Rocco on Tue 27/10/2009 10:14:32

Title: module - struct variable problem? (solved)
Post by: Rocco on Tue 27/10/2009 10:14:32
I recognized strange behavoirs with my struct.variables.
i use modules and structs.


// RPG.ash
struct Roc_Struct_RPG
{
  String name;
  int money;
  int searching;
  .
};  

Roc_Struct_RPG thief;
export thief;



//RPG.asc

function game_start()
{  

 thief.money = 1000;
 thief.searching = 5;
 
}



now i try to use that vars and get strange results,
when i use the vars in the RPG.asc file, all is fine the values are correct,


RPG.asc
player.say("My Money = %d", thief.money);   // value ist correct


but when i try to use the vars in another module or the room scripts.

othermodule.asc
player.say("My Money = %d", thief.money);   // value is wrong (always 0)



roomxx.asc
player.say("My Money = %d", thief.money);   // value is wrong (always 0)


i get vars with value 0.
what is wrong in this case?
Title: Re: module - struct variable problem?
Post by: skuttleman on Tue 27/10/2009 10:20:06
When you define a variable in a header file, you define a separate variable in every script.
Put this in RPG.ash:

struct Roc_Struct_RPG
{
   String name;
   int money;
   int searching;
   .
};


And put this in RPG.asc:

Roc_Struct_RPG thief;
export thief;
Title: Re: module - struct variable problem?
Post by: Rocco on Tue 27/10/2009 10:42:40
big thx, with the import addition, all works fine.  :)

RPG.ash script

struct Roc_Struct_RPG
{
   String name;
   int money;
   int searching;
   .
};

import Roc_Struct_RPG thief;