Author Topic: module - struct variable problem? (solved)  (Read 351 times)  Share 

module - struct variable problem? (solved)
« on: 27 Oct 2009, 10:14 »
I recognized strange behavoirs with my struct.variables.
i use modules and structs.

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

Roc_Struct_RPG thief;
export thief;
[/code]

[code]
//RPG.asc

function game_start()
{  

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

[/code]

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]
RPG.asc
player.say("My Money = %d", thief.money);   // value ist correct
[/code]

but when i try to use the vars in another module or the room scripts.
[code]
othermodule.asc
player.say("My Money = %d", thief.money);   // value is wrong (always 0)
[/code]

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

i get vars with value 0.
what is wrong in this case?
« Last Edit: 28 Oct 2009, 10:42 by Rocco »

skuttleman

  • Can you taste the thumbtacks?
    • I can help with AGS tutoring
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with story design
    •  
Re: module - struct variable problem?
« Reply #1 on: 27 Oct 2009, 10:20 »
When you define a variable in a header file, you define a separate variable in every script.
Put this in RPG.ash:
[code]
struct Roc_Struct_RPG
{
   String name;
   int money;
   int searching;
   .
};
[/code]

And put this in RPG.asc:
[code]
Roc_Struct_RPG thief;
export thief;
[/code]

Re: module - struct variable problem?
« Reply #2 on: 27 Oct 2009, 10:42 »
big thx, with the import addition, all works fine.  :)

RPG.ash script
[code]
struct Roc_Struct_RPG
{
   String name;
   int money;
   int searching;
   .
};

import Roc_Struct_RPG thief;
[/code]