GUI buttons don't change GlobalInt (SOLVED)

Started by InCreator, Tue 12/07/2005 00:09:44

Previous topic - Next topic

InCreator

Well, I really can't imagine what's wrong here:

Code: ags
 
if (button == 1)
  {        
  if (GetGlobalInt(110)!= 2) SetGlobalInt(110,(GetGlobalInt(110)+1));
  }   
 if (button == 3)
  {        
  if (GetGlobalInt(110)!= 0) SetGlobalInt(110,(GetGlobalInt(110)-1));
  }   


Basically, both buttons should change the value of GlobalInt 110.

One button decreases it to 0
Second one adds its value up to 2

Thing is, when the value of Globalint 110 is 0 or 2, you have to press button TWICE until it changes the value.

For example, if GlobalInt(110) == 2
I have to press button (3) twice to get value of 1

But if it's value is 1
a simple click on button nicely decreases it to 0
and vice versa.

What am I doing wrong?

Gilbert

I can't see what's wrong so far, but try to insert a display line and see if the decrease button was somehow (for some unknown reasons) considered to be pressed twice, like this:

Code: ags
 
if (button == 1)
Ã,  {Ã,  Ã,  Ã,  Ã,  
Ã,  if (GetGlobalInt(110)!= 2) SetGlobalInt(110,(GetGlobalInt(110)+1));
Ã,  }Ã,  Ã, 
 if (button == 3)
Ã,  {Ã,  Ã,  Ã,  Ã,  
  Display("blah!");
Ã,  if (GetGlobalInt(110)!= 0) SetGlobalInt(110,(GetGlobalInt(110)-1));
Ã,  }Ã,  Ã, 


Also, search for "110" in your script and see if there're more lines in it that will change its value (I think searching for "110" is probably better than for "GlobalInt", in case you used many other global ints in your game).

InCreator

#2
Well, it displays the message, but doesn't change the value of globalint, at the first time.
Second time, it shows the message, AND changes the value.

Not only when reducing, but adding to 0 aswell (with other button)

I spectate the value (assigned a gui label to show it all the time), it doesn't simply change. Yet, the first click is registered aswell. (I thought that ags just misses the first click) But no. Two messages, one change.

And, I went through global script, and disabled everything (remarked out) concerning globalint(110), only line that stayed is declaration on such thing (setting it to 0 at game_start)

nope.
I also tried using other numbers for indexing this int (for case if Globalint 110 it's somehow reserved by ags), no luck.

the gui script has nothing else than this (and label assigning), I provide full portion of this GUI code, just for case

GUI script:
Code: ags

if (interface == MOB) 
 {
   string buffer; // stuff to spectate the value
   StrFormat (buffer, "%d", GetGlobalInt(110)); // int2string
   naitur.SetText(buffer); // "naitur" is the label's script name
 if (button == 1)
  {        
  if (GetGlobalInt(110)!= 2) SetGlobalInt(110,(GetGlobalInt(110)+1));
  }   
 if (button == 3)
  {       
  if (GetGlobalInt(110)!= 0) SetGlobalInt(110,(GetGlobalInt(110)-1));
  }   
 }


I can't be doing anything wrong! :(
Why me?

I tried other things too, like making max and min value of some other numbers, it didn't help. AGS always gets stuck on lowest and highest number. whether they are 12 and 39 or 0 and 2.
Just when it reaches the "border" number, the button must be clicked twice.


I suspect 2 things:

first, this way to subtract and add 1 to globalint's value. Was that the right way? I recall someone suggesting something like

SetGlobalint(110)++
or
SetGlobalint(110,++)

or something similar in this forum decades ago..

and second... the AGS version is 2.7... yet, I use oldschool scripting much, maybe there's a conflict?


Gilbert

Quote from: InCreator on Tue 12/07/2005 03:24:01
I suspect 2 things:

first, this way to subtract and add 1 to globalint's value. Was that the right way? I recall someone suggesting something like
Seems correct.

Quote
SetGlobalint(110)++
or
SetGlobalint(110,++)

or something similar in this forum decades ago..

and second... the AGS version is 2.7... yet, I use oldschool scripting much, maybe there's a conflict?
Nope, don't do the ++ route, these should work only for real variables.

There doesn't seem to be a problem in your code, but in case there're something I missed, try the following instead, this is my usual code for increasing/decreasing stuff:

Code: ags
 
if (button == 1)
Ã,  {Ã,  Ã,  Ã,  Ã,  
Ã,  Ã, SetGlobalInt(110, GetGlobalInt(110)+1);
Ã,  Ã, if (GetGlobalInt(110)> 2)SetGlobalInt(110,2);
Ã,  }Ã,  Ã, 
 if (button == 3)
Ã,  {Ã,  Ã,  Ã,  Ã,  
Ã,  Ã, SetGlobalInt(110, GetGlobalInt(110)-1);
Ã,  Ã, if (GetGlobalInt(110)<0)SetGlobalInt(110,0);
Ã,  }Ã,  Ã, 


InCreator

Thanks for help, but I got it sorted out myself.

Problem was much simpler, as it always tends to be:

Apparently, the GUI labels (which I used for value display) won't refresh themselves in game steps, but only when something is done with gui, like a button clicked.

I found it out when I added third button, which had absolutely no interaction or code. Just a button.

Then made this "empty" click on decreasing button and pressed the third, interactionless one - the label changed to right value though click on third button should have done absolutely nothing. My best guess is that "if interface == x" is called only when GUI itself is being interacted some way.

All was clear then - I simply placed label-changing lines into repeatedly_excecute in global script and it started to refresh value correctly.

Though the value-label was just for test, my game has graphical version of similar thing:
The thing I worked on was mobile phone menu, with graphical images changing, just like on real cellphone (phonebook, settings, etc), and routlines for changing the menu picture were also in GUI script. They scrolled incorrectly, so that's what led me to this error. So now I know that even if not seen, the values were still right and also where to put these lines for correct display.

If CJ had noticed this thread, he could have saved me for trying to figure this out so long, but well, I'm glad i got this to work after all.



Gilbert

Odd, if it's just a GUI label, it should be automatically be changed next game loop whenever you change it.

InCreator

#6
So, does AGS go through GUI script in each loop?
Well, it definetly didn't seem so  :(

btw, it's a popup modal, if that changes anything.
AND, it pauses the game.

It pops up when inventory item has been used on character.
I tried it when walking, character stopped in the middle of the walk. Also, Displayspeech under buttons shows speech, but no talking animation, so it's quite clear that pause is there.

EDIT: Oh yes, the labels change. On static (always-on-screen) GUIs like statusbar, even if the cellphone gui is displayed. The game is paused, but moving mouse around shows @overhotspot@ correctly. It's just this popup-modal that won't change and acts paused along with game.

(OMG, my 1000th POST!)

Gilbert

Well if it's popup-modal, I think that's what causing the problem, personally I don't find the popup-modal mode very usefully, I'd rather use persistent/normal and script something into it if I don't want something to happen while the GUI's on.

The @overhotspot@ or @score@ things is a different story, they're controlled internally by the engine, so will be updated always.

Pumaman

Quote from: InCreator on Tue 12/07/2005 06:07:43
If CJ had noticed this thread, he could have saved me for trying to figure this out so long, but well, I'm glad i got this to work after all.

I think that's a bit harsh considering that I was asleep between the time you first posted this thread and the time that you resolved it.

Anyway, what do you have on the GUI Label? Are you using something in repeatedly_execute to update it with the globalint status, or are you using the @GI110@ thing? It's possible the latter method has a refreshing problem.

InCreator

QuoteI think that's a bit harsh considering that I was asleep between the time you first posted this thread and the time that you resolved it.

I didn't mean to be harsh, sorry if I sounded like that.

@GI110@? It's first time I hear about such thing...

Pumaman

Quote from: InCreator on Tue 12/07/2005 21:03:22
@GI110@? It's first time I hear about such thing...

Ok, then how are you keeping the label up to date with the global int value?

InCreator

#11
string buffer;
StrFormat (buffer, "%d", GetGlobalInt(110));
naitur.SetText(buffer);

Like this.

The whole problem was that these lines were in GUI script instead of repeatedly_excecute so the label didn't refresh in time, but only when some button was clicked on this gui.

Gilbert

I see your problem now (didn't notice that label part), why don't you modify the label AFTER the values are changed?

Code: ags

if (interface == MOB) 
 {
Ã,  Ã, if (button == 1)
Ã, Ã,  Ã, {Ã,  Ã,  Ã,  Ã,  
Ã,  Ã,  Ã, Ã,  if (GetGlobalInt(110)!= 2) SetGlobalInt(110,(GetGlobalInt(110)+1));
Ã,  Ã,  }Ã,  Ã, 
Ã,  Ã, if (button == 3)
Ã, Ã,  Ã, {Ã,  Ã,  Ã,  Ã, 
Ã,  Ã,  Ã, Ã,  if (GetGlobalInt(110)!= 0) SetGlobalInt(110,(GetGlobalInt(110)-1));
Ã,  Ã,  }Ã,  Ã, 
Ã,  Ã, string buffer; // stuff to spectate the value
Ã,  Ã, StrFormat (buffer, "%d", GetGlobalInt(110)); // int2string
Ã,  Ã, naitur.SetText(buffer); // "naitur" is the label's script name
 }


SMF spam blocked by CleanTalk