Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Bijulinus on Wed 19/09/2007 13:25:24

Title: Global variables and ...
Post by: Bijulinus on Wed 19/09/2007 13:25:24
Hello, I've a big doubt and I'm sinking in the manual  ::)

In the new version of AGS, HOW do I do variables globally accessable?
Or better, a struct globally accessable?

Another thing, stupid but that's annoying me: how do I cast int to strings???

Thanks a lot :o
Title: Re: Global variables and ...
Post by: Khris on Wed 19/09/2007 13:37:20
The way to do it didn't change in the new version (regardless whether you're speaking of 2.8 or 2.72). Export the variable after its declaration, then import it in the header.

Int to string:

Int i=3;
String s=String.Format("%d", i);
Title: Re: Global variables and ...
Post by: Bijulinus on Wed 19/09/2007 13:52:09
Could you make an example? Specifying where the instructions are put?

Thanks
Title: Re: Global variables and ...
Post by: Khris on Wed 19/09/2007 13:58:31
// header

struct mystruct {
  int a;
  String name;
};

import int var;

import mystruct test[8];

// global script

int var;
mystruct test[8];

export var, test;


Just remember: export only the name, but import the whole declaration.
Title: Re: Global variables and ...
Post by: Bijulinus on Wed 19/09/2007 14:04:51
Thanks! I only knew the infamous GetGlobalInt(... !
;D ;D
Title: Re: Global variables and ...
Post by: Ashen on Wed 19/09/2007 14:23:21
In future, READ THE BFAQ (http://americangirlscouts.org/agswiki/Scripting%2C_Code_%26_Interaction#Working_with_variables:_the_basics) before posting.

Admittedly it doesn't mention structs (it's only 'the basics', after all), but it deals with making other variable types Globally accessable, in detail.

EDIT: I've updated the Inserting variables into speech/messages (http://americangirlscouts.org/agswiki/Scripting%2C_Code_%26_Interaction#Inserting_variables_into_speech.2Fmessages) entry to also mention ints.