Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Icey on Sat 19/03/2011 05:42:34

Title: GUI not visible
Post by: Icey on Sat 19/03/2011 05:42:34
For some reason one of my GUI's wont show in this room.
(http://www.pictureshoster.com/files/jr69ayr1w7gsy8ghp2xu.png)
When the cursor goes over the enemy it displays a GUI

//Here is the code I use for the fight scenes.


  Object *cat = Object.GetAtScreenXY(mouse.x, mouse.y);
  Object *oat = Object.GetAtScreenXY(mouse.x, mouse.y);

if(Shiva.X){
  if(Shiva.Y){
  enemyHP.Visible = ((cat != null) || (oat != null)); // where gOver is the name of the GUI you want to have turned on or off
  target.NormalGraphic = 521;// Shiva icon change
  OE.NormalGraphic = 183;
 
}
}
strengths.Text = String.Format("HP: %d", playerHP);//Menu health
    pairHP.Text = String.Format("HP: %d", playerHP);//pair health
   
   enemystats.Text = String.Format("HP: %d", EnemyST);//Enemy health



Now there is an X amount of room with fights. Each room contains this code in the Repeatedly execute area.
Each room it works in.

Another real fight room.
(http://www.pictureshoster.com/files/xgdvsmijkokxq8jdkih7.png)

First beta fight.
(http://www.pictureshoster.com/files/dmgwrobieoupvh05knr.png)

Reason's why
The object is about as big as the room do to the animations used for it.
   - I tried setting the baseline to 200. = fail
   - I tried setting other obj's baseline to 1. = fail
   - I change the name Shiva in the script to eye(hence the eyes on the enemy) and the gui shows accept it just stays on.









Title: Re: GUI not visible
Post by: Khris on Sat 19/03/2011 06:04:41
I'll just mention the obvious stuff:

Is the room's rep_exe linked properly?
Is the function called at all?
Why is the code's indentation messy, making it less readable?
Title: Re: GUI not visible
Post by: Icey on Sat 19/03/2011 06:23:48
What do you mean by linked?

Just checked. The function is called.

Sorry. I have it like that to separate things in the script and so I remember were every thing is.


//Here is the code I use for the fight scenes.


 Object *cat = Object.GetAtScreenXY(mouse.x, mouse.y);
 Object *oat = Object.GetAtScreenXY(mouse.x, mouse.y);

if(Shiva.X){
 if(Shiva.Y){
 enemyHP.Visible = ((cat != null) || (oat != null)); // where gOver is the name of the GUI you want to have turned on or off
 target.NormalGraphic = 521;// Shiva icon change
 OE.NormalGraphic = 183;
 
}
}
strengths.Text = String.Format("HP: %d", playerHP);//Menu health
   pairHP.Text = String.Format("HP: %d", playerHP);//pair health
 
  enemystats.Text = String.Format("HP: %d", EnemyST);//Enemy health

Title: Re: GUI not visible
Post by: Khris on Sat 19/03/2011 06:32:11
This makes no sense:

  Object *cat = Object.GetAtScreenXY(mouse.x, mouse.y);
  Object *oat = Object.GetAtScreenXY(mouse.x, mouse.y);


Shouldn't it be

  Character *cat = Character.GetAtScreenXY(mouse.x, mouse.y);
  Object *oat = Object.GetAtScreenXY(mouse.x, mouse.y);


Since the mouse seems to be hovering over a character, with your code oat and cat are supposedly both null, thus ((cat != null) || (oat != null)) is false, thus the GUI's visibility is set to false.
Title: Re: GUI not visible
Post by: Icey on Sat 19/03/2011 06:41:22
It's hovering over a Object. Each enemy is named Shiva due to the fact that it make's it a lot more easier for me to code because all I have to do is change things around here & there.

Well I don't really understand that whole oat & cat thing. Seeing how monkey gave me this

function repeatedly_execute()
{
  Character *cat = Character.GetAtScreenXY(mouse.x, mouse.y);
  Object *oat = Object.GetAtScreenXY(mouse.x, mouse.y);
  gOver.Visible = ((cat != null) || (oat != null)); // where gOver is the name of the GUI you want to have turned on or off
}

I couldn't really get it to work so I edited it. It's been working up until now.
Title: Re: GUI not visible
Post by: monkey0506 on Sat 19/03/2011 07:20:57
cat and oat are just examples of what I have come to use as the names of temporary variables when I need to check when something is at given coordinates (like with GetAtScreenXY). The logic behind it is basically that cat would represent the Character at the given coordinates, and oat would represent the Object at the given coordinates.

It's simply the way I personally name the variables pointers, which is meaningless unless you decide to adopt the same thing..the name of variables/pointers is irrelevant so long as they are properly used.

Think about it for a second though..if you set X=5 and Y=5 then turn around and check X!=0..under what circumstances would you also have to check Y!=0 when you know that X==Y?

The code I gave you will make the GUI visible any time the mouse is placed over a character or an object, as per your original request.

You modified that by adding the additional condition that the one object in the room named Shiva (despite your saying that they're all named this..only one of these objects can possibly have this script name (per room, since they are unrelated)) has non-zero X and Y coordinates..

How did you go about checking that the function is being called? Did you use a breakpoint, a Display statement, or what did you do? This is important for us to be sure that your results were actually verified and that you haven't misinterpreted something.

QuoteI couldn't really get it to work so I edited it. It's been working up until now.

So..if I'm reading this correctly..you couldn't get it working, so you edited it..but it was working..until you edited it. Wait..WHAT?? I'm sorry..this is just..I don't even.

Also, I'm going on a lot about indentation lately, and I seem to have gotten Khris on the bandwagon, but seriously, it is automatically handled for you..you have to intentionally go out of your way to break the indentation like you have..saying that you make your code an unreadable mess in order to make it more structured, organized, and readable is a lie and no one believes you. I'm not trying to be rude in saying that, I'm just being honest with you.

Oh, and Khris, it would be possible for both Character.GetAtScreenXY and Object.GetAtScreenXY to return non-null since they don't actually check against what is the top-most visible item, but simply do a raw check against whether there is a character or an object (respectively) at the given coordinates. If you need to determine between two non-null pointers which is the top-most visible one, you could use GetLocationType of course. ;)
Title: Re: GUI not visible
Post by: Icey on Sat 19/03/2011 07:35:02
When I first used the code you gave me I could get it to work. So I tried some things until it worked. there are other fighting rooms with a enemy who has that code and it works.

Also, I do have my scripts like that so (I) understand them since I'm working on them. However ever when I post them I try to neaten them up for you guys.

Also, When I changed the script name Shiva.x/y to eye.X/y The gui shows but it just stays there until I tell it to go away.
[after battle]
or
[death to player]
Title: Re: GUI not visible
Post by: monkey0506 on Sat 19/03/2011 16:56:00
So now you're saying that the code I gave you worked. It worked, so you modified it. After you modified it, it worked. Because it was working so well, you tried it in some other rooms, where it worked. In short, you're saying that the code I gave you works. That's good.

If you want to insist that this code is more readable than using some proper indentation style (there are several which validly do make code more readable), then I'll stop bringing it up to you. Still, none of us believe you, and I'm sure that deep down inside you don't either, but oh well, I'm done with it at this point.

As I said before, the (script) name of your objects is absolutely irrelevant. The problem is not the script name of your objects. The problem is your logic. Just for fun, try this for me. Create a new GUI with a display type of "Normal, initially off". Set its Z order to 1000. Set its script name to gMonkey. Create a label on the GUI. Set its name to lblMonkey. None of the other properties of the label are relevant so long as you can actually see the text on the label.

Now, in the room's script, do the following: 1) in the room_Load function, add this line:

  gMonkey.Visible = true;

2) in the room's repeatedly execute function (which for rooms by default is NOT named "repeatedly_execute" but rather "room_RepExec"), add this:

  lblMonkey.Text = String.Format("Shiva X: %d, Shiva Y: %d", Shiva.X, Shiva.Y);

Run the game, and go to that room. Try moving the mouse around and see if the label ever changes. Tell me what type of coordinates you see displayed on that label (you may need to write down several if Shiva moves). After you tell me that, delete the gMonkey GUI and remove those two lines from your room script.

The problem isn't the code I gave you, because the code I gave you was tailored to the specific purpose which you described. Later you wanted to use that code for a different purpose, but since you did not understand it, you couldn't get your modified versions to work the way you wanted. The problem is your logic, and your lack of understanding of the code (or it would seem, programming in general). I don't mind helping you, in fact I would like to see this issue resolved for you, but you have to listen to what I'm telling you to do and follow through with it, or you're not going to get the results that I'm describing.
Title: Re: GUI not visible
Post by: Icey on Sat 19/03/2011 18:34:45
Ok I will try this.

Also I have 2 other rooms that have this edited version of the code. the first time I edited your code was in my beta room. it worked well but I was not planning on using that room any more. When I took the edited version and put it in two other rooms it worked just like how I had it the first time I used it.

I really want this to work so I am listening to you :)

Title: Re: GUI not visible
Post by: Icey on Sat 19/03/2011 18:44:36
It says Shiva x:0 Shiva y:202 So this means that gui is off screen right

I added this and the gui is still not there. Btw the room is the same size as the other 2 battle rooms.
enemyHP.SetPosition(222,152);
Title: Re: GUI not visible
Post by: monkey0506 on Sat 19/03/2011 22:05:11
Wait, isn't Shiva the name you used for your Objects? Either way you're checking that Shiva.X is non-zero, and you've just said that Shiva.X is always 0..you don't see the problem yet? Coz I'm not sure that I could even possibly make it any more obvious...:-\
Title: Re: GUI not visible
Post by: Icey on Sun 20/03/2011 00:00:48
Well I guess you want me to now fix the gui's position?

Well I did that accept it still wont show.

Also when I tried what you said in another battle room the gui position is at (222,152) so I put enemyHP.SetPosition(222,152); in the room_RepExec.

Like I asked before, is it because the enemy is as big as the screen?
Title: Re: GUI not visible
Post by: monkey0506 on Sun 20/03/2011 00:36:26
Why do you think that enemyHP.SetPosition is going to affect Shiva.X? Is Shiva a GUIControl? An Object? A GUI? You are checking Shiva.X, but what is Shiva??

If Shiva is a GUIControl on the enemyHP GUI, then changing enemyHP's position will not in any way affect Shiva.X, though it will affect where Shiva appears on-screen (since GUIControl.X is relative to the OwningGUI.X and not absolute). In any other conceivable case changing enemyHP's position will not directly have an effect on Shiva.X.

You are still checking that Shiva.X is non-zero and yet Shiva.X is still always zero. Fix that, and it will work. I don't care about enemyHP's position. I only care about Shiva.X..because that is what you are checking.

Edit: On a slightly related note, this is a great argument for using naming conventions for global script objects (please don't confuse this with the AGS Object type, I mean any instance of a non-basic data type) that reflect the data type..like cCharacter or oObject.

Oh, and it might be related to the enemy being the same size as the screen IFF (IFF: If, and ONLY If) Shiva is the enemy and Shiva is an Object and that is the reason why you have Shiva.X set to 0 and are not changing it..but then it wouldn't be an issue with Shiva.X being 0..it would just be that you are checking that Shiva.X is non-zero when you know for a fact that it is always zero. In fact, regardless of whether or not Shiva is an Object (or indeed regardless of whatever else it may be), and regardless of whether or not Shiva is the enemy (or whatever else it may be)..the problem has nothing to do at this point with what Shiva is. The problem at this point is only exclusively that you are deliberately checking a condition that you absolutely know is false, and expecting it to be true. That is your problem.
Title: Re: GUI not visible
Post by: Icey on Sun 20/03/2011 03:05:10
Ok it seemed we fixed it yet it seemed we already solved it earlier. The gui just sits there like before when I changed Shiva.X/Y to eye.X/Y.

However I still have to think you because I just a lit more about this. And if this happens again I know how to fix it :)

Thanks Monkey for being patience with me.
Title: Re: GUI not visible
Post by: monkey0506 on Sun 20/03/2011 03:24:12
So you fixed it even though it was already fixed earlier??

Seriously..I don't understand what you're trying to say. I don't even know whether or not this problem has been solved.

When you say that the "gui just sits there" I feel like it's not working the way you want it to..but yet you said if the issue arises again you'll know how to fix it.

I am at a complete loss..I'm really sensing a language barrier here causing some issues..but the problem had nothing to do with what language you speak..the problem was an issue of logic, nothing more, nothing less. If you can't think logically then it doesn't matter what language you're speaking (or attempting to program in), you're not going to be able to properly convey your point.
Title: Re: GUI not visible
Post by: Icey on Sun 20/03/2011 05:23:23
No what I mean is that the way you fixed it was similar to what I change earlier. Except that the way you fixed it is the way I need it to keep going.

The GUI sits there still because the obj is as big as the screen there for it will stay until I tell it to go away.

So with this said, We had fixed it earlier just not the right way.
Title: Re: GUI not visible
Post by: Khris on Sun 20/03/2011 17:46:58
Just thinking about how you copy paste this dodgy piece of code around the rooms makes the hairs on my neck stand up. You are happily raping the very idea of OO.
Debugging this is going to be a nightmare, I hope you do know that already.

Sorry for not being productive at all, I just wanted to get it off my chest.
Title: Re: GUI not visible
Post by: Icey on Sun 20/03/2011 19:03:23
So far there are no bugs. I am half way done with this game. There are just a few things I need to get done.

Sprites
1 BG
music
sound
2 gui's
Spell check
Title: Re: GUI not visible
Post by: monkey0506 on Mon 21/03/2011 00:41:13
Sprites, Music, Sound, and Scripting..

..you're right, your game is almost finished! :-\
Title: Re: GUI not visible
Post by: Icey on Mon 21/03/2011 04:01:32
I have been at this game for 3 months now. It is almost done due to how much I spend working on my game. However I think it should be done next month.
Title: Re: GUI not visible
Post by: Icey on Wed 13/04/2011 23:34:48
I didn't see a reason to start a whole new topic that is sorta based on the same thing.

I have a Indicators to Display hP on GUI's.

through all the battles in the game the last one for some reason wont show the GUI's. There are 2 GUI's
-My_Hp
-EnemyHP

Bow I did what monkey said a it shows that GUI's are not off screen, There in fact where I set them to be, I tried to make it visible before the screen loaded and after the screen loaded to see if it is really there. I tried to Tween it's transparency to 0 to make it visible. However they are still not showing. I read through the script and yet there is nothing there to stop it from bring visible.

Example of whats called when you attack.

  ///////////////////////////////////////////
   Enemy_Hp2.Visible = false;
   Enemy_Hp2.TweenTransparency(0.1, 100);
   Enemy_Hp2.SetPosition(420, 215);
   Enemy_Hp2.Visible = true;
   Enemy_Hp2.TweenTransparency(0.5, 0, eLinearTween, eNoBlockTween);
   Enemy_Hp2.TweenPosition(0.8, 420, 215, eEaseOutTween, eBlockTween);
      Enemy_Hp.Visible = false;
   ///////////////////////////////////////////


Example of whats called when your attacked.

   ///////////////////////////////////////////
   HP1.Text = "15";
   HP1.TextColor = 4;
   My_Hp2.Visible = false;
   My_Hp2.TweenTransparency(0.1, 100);
   My_Hp2.SetPosition(392, 270);
   My_Hp2.Visible = true;
   My_Hp2.TweenTransparency(0.5, 0, eLinearTween, eNoBlockTween);
   My_Hp2.TweenPosition(0.8, 392, 270, eEaseOutTween, eBlockTween);
      My_Hp2.Visible = false;
   ///////////////////////////////////////////




Title: Re: GUI not visible
Post by: Khris on Wed 13/04/2011 23:52:43
Judging from the screenshots your game is 320, is it actually 640 but uses upscaled 320 graphics?
Because the coordinates you're using are off-screen for a 320 game.

If we're talking scrolling rooms, keep in mind that GUIs are positioned using screen coordinates, not room coordinates.
Subtract GetViewportX() and GetViewportY() to get to the screen coords.
Title: Re: GUI not visible
Post by: Icey on Thu 14/04/2011 00:02:49
The room size is around 500 x by something however there is a room before that is also a little bigger then 320, All I had to do was select the X, Y in the room and it worked like I wanted it to. But why does it not do the same here.
Title: Re: GUI not visible
Post by: monkey0506 on Thu 14/04/2011 01:45:10
GUI, Overlay, and Mouse positions are always (always, always, always) screen-coordinates. Character, Hotspot, and Object positions are room-coordinates.
Title: Re: GUI not visible
Post by: Khris on Thu 14/04/2011 01:47:52
I just told you, GUIs are positioned in relation to the screen, not the room.
Screen coordinates are in the range of x:0-319, y:0-199/239.

Try this:

  ///////////////////////////////////////////
   Enemy_Hp2.Visible = false;
   Enemy_Hp2.TweenTransparency(0.1, 100);
   Enemy_Hp2.SetPosition(420 - GetViewportX(), 215 - GetViewportY());
   Enemy_Hp2.Visible = true;
   Enemy_Hp2.TweenTransparency(0.5, 0, eLinearTween, eNoBlockTween);
   Enemy_Hp2.TweenPosition(0.8, 420 - GetViewportX(), 215 - GetViewportY(), eEaseOutTween, eBlockTween);
   Enemy_Hp.Visible = false;
   ///////////////////////////////////////////
Title: Re: GUI not visible
Post by: Icey on Thu 14/04/2011 02:11:50
Thanks, It works.