Do I need to import GUI pointers?

Started by Ashen, Tue 27/09/2005 13:56:47

Previous topic - Next topic

Ashen

So, I know how to make a GUI pointer (GUI *myGui;), and I know that if I put that in the script header, the myGui pointer will be available in every room/script. BUT if I set myGui (myGui = gInventory;) in the global script, it's only usable in the global script - unless I also put a myGui = gXx in (for example) a room script, it crashes as a null pointer.

It's not, obviously, a major problem - I can just watch what/where I call - I was just wondering if there was a way to keep the settings across scripts.
I know what you're thinking ... Don't think that.

strazer

#1
You can export/import pointers just like variables:

Code: ags

// main global script

GUI *myGui; // define pointer for use in global script
export myGui; // export pointer for use in room scripts


then

Code: ags

// main script header

import GUI *myGui; // import pointer for use in all rooms


or

Code: ags

// room script

import GUI *myGui; // import pointer for use in this room


I hope I have understood you correctly.

Edit:

Quote from: Ashen on Tue 27/09/2005 13:56:47
So, I know how to make a GUI pointer (GUI *myGui;), and I know that if I put that in the script header, the myGui pointer will be available in every room/script.

If you define variables/pointers in the script header, a seperate variable will be created for the global script and every room script. So if you change the pointer in the global script, it doesn't affect the pointer in the room script.

Ashen

QuoteI hope I have understood you correctly.

Yes, you have. I thought I'd tried every combination of import/exporting them - including that one - but I guess not, as it now works. Thank you, although I now feel like a total n00b.
I know what you're thinking ... Don't think that.

SMF spam blocked by CleanTalk