module - struct variable problem? (solved)

Started by Rocco, Tue 27/10/2009 10:14:32

Previous topic - Next topic

Rocco

I recognized strange behavoirs with my struct.variables.
i use modules and structs.

Code: ags

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

Roc_Struct_RPG thief;
export thief; 


Code: ags

//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,

Code: ags

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.
Code: ags

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


Code: ags

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?

skuttleman

When you define a variable in a header file, you define a separate variable in every script.
Put this in RPG.ash:
Code: ags

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


And put this in RPG.asc:
Code: ags

Roc_Struct_RPG thief;
export thief;

Rocco

big thx, with the import addition, all works fine.  :)

RPG.ash script
Code: ags

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

import Roc_Struct_RPG thief;

SMF spam blocked by CleanTalk