Hi guys,
Recently with the help of people here, I was able to get something to work with arrays + pointers. This is what it was:
#define guiAmount 32
GUI* guiList[guiAmount];
(in game start)
guiList[0] = gPanel; guiList[1] = gHelp; guiList[2] = gSave; guiList[3] = gLoad; guiList[4] = gRestart...etc
I used the same concept with buttons, and it also worked (Button* borderListTct[borderAmount])
How can I use this with a list of bools? This is my list of bools I declared at the top of my global script:
bool bIsGuiOpenA = false;
bool bIsGuiOpenB = false;
bool bIsGuiOpenC = false;
bool bIsGuiOpenD = false;
bool bIsGuiOpenE = false;
I tried this and I get an error:
#define gleamAmount 5
Bool* gleamList[gleamAmount];
(in game start):
gleamList[0] = bIsGuiOpenA; gleamList[1] = bIsGuiOpenB; gleamList[2] = bIsGuiOpenC; gleamList[3] = bIsGuiOpenD; gleamList[4] = bIsGuiOpenE;
The function Im trying to use all that with:
function showGleamType_HideOthers(bool bType)
{
// first make the type "true"
if (bType == false) bType = true;
// second, make all the others false
int i;
while (i < gleamAmount) //5 types of gleams (A,B,C,D,E)
{
if (bType != gleamList[i])
{
if (gleamList[i] == true) gleamList[i] = false;
}
i++;
}
}
Note that "(bool bType)" isnt exactly what I want, Im not sure how to write so that its "one of the elements in the array of gleamList"...which are all bools.
What I want this function to do is set the selected bool to true and all the other ones that are in the list to false... so when I use it, it would look someting like this:
showGleamType_HideOthers(bIsGuiOpenA); //show typeA, hide all other types
Im sure Im almost there...
First of all AGS only supports pointers for managed objects. GUIs, GUI Controls, Characters, Objects are in this category; dasic data types, functions, custom structs are not. So to answer your question tyou can't have pointers to bool but you could use a bool array instead, perhqaps something like this...
#define GLEAM_LEN 5
bool gleamList[GLEAM_LEN];
function showGleamType_HideOthers(int type)
{
// first make all false
int i;
while (i<GLEAM_LEN) //5 types of gleams (A,B,C,D,E)
{
if (bType != gleamList[i])
{
if (gleamList[i] == true) gleamList[i] = false;
}
i++;
}
// second make the type "true"
gleamList[type] = true;
}
However, it seems like you want to be able to turn on one GUI and turn off all the others in a specific group. To do that you could just do something like the following ...
function showGleamType_HideOthers(GUI *enable) {
// second, make all the others false
int i;
while (i<guiAmount) (A,B,C,D,E) {
if (guiList[i]==enable) {
guiList[i].Visible = true;
}
else {
guiList[i].Visible = false;
}
}
}
Hey RickJ,
Well what Im doing is each bool in the gleamList is for activating a certain loop animation within a view. If a certain type of GUI is opened (say, type A, for example), it sets the bool bIsGuiOpenA to true and all the others to false...meaning it will run loop 0 in viewX. If it were a type B Gui opened, I would have bIsGuiOpenB set to true and the others to false...now run loop 1 of viewX instead.
I integrated what you suggested, but the only problem is when I get to the function "showGleamType_HideOthers(int iType)"
Since the array is bool, when I enter showGleamType_HideOthers(0)
(to hide the 1st element in the array), it returns an int... I think theres a problem with the array? As in, I dont want to use the "value" of those bools in the array, I want to use their "names" so I set them true or false later in the function, one by one.
For example, in this case: gleamList[iType] = true;
doesnt set bIsGuiOpenA to true, it sets gleamList[0] to true...which is like saying set "false to true" (because I initialize all those bools to false at the beginning).
How do I actually get to set the name of the bool variable to true or false? (Hope this makes sense!)
I'm pretty sure I've explained this already: what you want isn't possible. Using variable names simply doesn't work that way.
You have to use an enum instead:
// in Global.ash
enum iType {
bIsGuiOpenA = 0,
bIsGuiOpenB = 1,
bIsGuiOpenC = 2,
bIsGuiOpenD = 3,
bIsGuiOpenE = 4
};
Now you can reference the array elements using the enum elements:
#define gleamAmount 5
bool gleamList[gleamAmount];
function showGleamType_HideOthers(iType t) {
int i;
while (i < gleamAmount) {
gleamList[i] = false;
i++;
}
gleamList[t] = true;
}
Note that to check the bool, you don't use if (bIsGuiOpenC), you'd use if (gleamList[bIsGuiOpenC]).
Hey Khris,
You're right, I wasnt sure if it was the same thing but it is...since I learnt mel script a while ago I have a hard time "unlearning" a few things from that way of scripting thats different with ags...doh!
Well thanks again, Ill try this out now :)
Ok nice, this works perfect!
Is it "safe to say" pointers are one of the most difficult concepts in C++/scripting?
Short answer: no.
Once you get pointers, they are very easy and comfortable to use.
After a few years of coding with AGS I'd say the one thing I find most difficult is organizing your code and data structures in a way that allows you to pick it right back up after a longer pause.
I guess I could say its still something I struggle with but Im sure eventually it will sink in. Im surprised though that...if this is weird to say, scripting is actually "fun"...its satisfying being able to solve scripting "puzzles" and then seeing the results on screen!