I've had reports that certain things are occasionally not working in my game. There's one instance where you have to give Item 'A' to a character. This will set GlobalInt(6) to 2. Once this is done, you can then give Item 'B' to this character. I'm getting reports that even after giving Item A to this character, the game won't let you give Item B to the character. It gives the response that would normally come up if GlobalInt 6 was either 0 or 1.
I've checked and rechecked MANY times and there is absolutely no instance anywhere in the game of SetGlobalInt (6, 0) or SetGlobalInt (6, 1). It also only seems to be this way some of the time. I've tried the game myself and it works the way it should but for some people, sometimes it happens this way.
I've had similar problems happen in other spots of the game - instances where the only solution I can think of is that something somewhere is setting a particular GlobalInt to a value it shouldn't be, even though there's no code ANYWHERE that's doing so (in an obvious way).
That's the reason why Item A sets GlobalInt 6 to 2 as opposed to just setting it to 1. I had the same problem before, in that the game seemed to have automatically made GlobalInt 6 equal 1 right from the start of the game. I changed the SetGlobalInt instance to 2 and the response to 2, and it worked fine... it was a quick way of fixing the problem but I never did find out why the game seemed to think GlobalInt 6 equalled 1...
I have no idea, I can only think that it's a bug. Any ideas, anyone?
Hmmm I'm not sure, but maybe it's caused by some misplacements of the {}'s, else etc (maybe it IS a bug).
My suggestion is, try adding a line like below in company with a "set" or "get" globalint action:
Display("%d",GetGlobalInt(6)); //if it's not #6, change it
So for example if you want to set it to some value:
if (blah) {
SetGlobalInt(6,2);
Display("%d",GetGlobalInt(6));
//blahblah
}
If you want to perform some action according to its value:
if (GetGlobalInt(6)==1) {
//blablablah
Display("%d",GetGlobalInt(6));
} else if (GetGlobalInt(6)==2) {
//blablablablah
Display("%d",GetGlobalInt(6));
} else if {...}
This may help in debugging and tracking of the variable.
Thanks Gilbot. I did try that but everything was fine for me, just as it was before. That's one of the problems, it was only one person that has reported this problem, so it seems to happen randomly or at least is triggered by something it shouldn't be.
What would be really handy (I don't know if this sort of thing would be possible) is if in one of the future versions of AGS, there was a debugging feature with which you could use a button to call up a box that let's you know what the current values of all GlobalInts are at that time.
I'm not quite sure, but that sounds strange, like some memory corruptions during runtime. Actually I export and import global variables crazily myself, which never fails for me, and I don't bother to use the globalint anymore (though I often suggest other people to ;D ).
Did the strange behaviour happen frequent on his computer ? Or just rarely?
It's possible that there's a bug, but GlobalInts are such basic functionality that I'm sure something would have been reported before now if that was the case.
The most likely cause is some sort of scripting logic error, if for example the player does things in a different order to how you expect.