Hey,
so I am trying to have a 60% opacity layer of black as a room object to simulate nighttime. But AGS does not recognize it and just shows nothing. I have had this problem before and could "fix" it, by using the spray tool to create the layer, wich worked to some point, but was a lot of work to try to get to look neat. So it seems like the problem is only with constant opacity? Can someone explain and maybe offer a solution?
Quote from: Racoon on Thu 16/04/2020 18:33:46
Hey,
so I am trying to have a 60% opacity layer of black as a room object to simulate nighttime. But AGS does not recognize it and just shows nothing. I have had this problem before and could "fix" it, by using the spray tool to create the layer, wich worked to some point, but was a lot of work to try to get to look neat. So it seems like the problem is only with constant opacity? Can someone explain and maybe offer a solution?
It should normally work. Can you tell how do you do that exactly?
(although I'd suggest to use a GUI, as it's simplier and may be used in many rooms)
Hm, I just make a black layer. Turn opacity to 60% and export as png. Then I added it as a sprite and put it in the room. But it does not work. The only way it works is if I spray it with the spray tool, but even then: It looks nice enough in my paint program, but when I add it as a sprite most of the time it shows white patches still.
I tried to put an 100% opacity object behind it, with the result that the the object is shown with the dark layer above it, but apart from that the dark layer is not visible. Maybe I am doing something wrong, but I dont know what..
Quote from: Racoon on Thu 16/04/2020 18:54:20
Hm, I just make a black layer. Turn opacity to 60% and export as png. Then I added it as a sprite and put it in the room.
Oh, so you are making a png image with 60% alpha value? Have you tried making an opaque black sprite and set object Transparency in AGS?
Regarding the error, when you import sprite, do you have "Keep alpha channel" checkbox on? Is the sprite 32-bit?
(Note, with GUI you dont even need to make sprites, as you may set black background color in the editor.)
When you imported the sprite, was it set to "leave as is" or use the top left pixel, or something else? It should be imported with "leave as is" otherwise the whole sprite will be considered the background part of the sprite.
I'm guessing it's that, anyways.
And a GUI is going to be more flexible, especially when an object cannot be called in a global script. But it always helps to learn what it is you're doing wrong for future reference regardless of whether you stick to an object or a GUI.
Quote from: ManicMatt on Thu 16/04/2020 19:05:45
When you imported the sprite, was it set to "leave as is" or use the top left pixel, or something else? It should be imported with "leave as is" otherwise the whole sprite will be considered the background part of the sprite.
I'm guessing it's that, anyways.
And a GUI is going to be more flexible, especially when an object cannot be called in a global script. But it always helps to learn what it is you're doing wrong for future reference regardless of whether you stick to an object or a GUI.
Ahh, yes that was the problem. Thanks a lot!
Yeah, I am trying to get more flexible, but since I am completly new to coding working with GUI always seems like the more complicated step.
Don't be afraid of GUIs, they're your friend. (nod)
Simple steps:
- Create new GUI
- size it to the game res, so it fills the entire screen
- set it to non-clickable, so it won't be in the way of clicks
- Set the BG color to black and no border
- Set transparency to 60%
- name it: gNight (as an exemple)
- set it to normal and not visible
Now you can just call it in script: gNight.Visible=true; to make it night and gNight.Visible=false; to make it back to daytime. ;)
And if you want something more "fancy" you can make it fade in/out if you like.
Yay! I finally solved someone's conundrum hahaha!
I understand what you mean, I was at first avoiding GUI things but it turned out to not be as difficult as I thought it would be. Good little tutorial by Cassiebsg here!
Quote from: ManicMatt on Fri 17/04/2020 08:25:10
Yay! I finally solved someone's conundrum hahaha!
I understand what you mean, I was at first avoiding GUI things but it turned out to not be as difficult as I thought it would be. Good little tutorial by Cassiebsg here!
Easy as eggs on a summers' day ManicMatt (nod)
Indeed!
Thanks to you as well Cassiebsg& Crimson Wizard! I will try out to make a GUI the next time I want to inlcude something like that.
And I am really greatful, that often my problems are solved within a day everytime I post a question. A lot of nice people around.
Hey, so I´ll reuse this thread for some more questions.
I am almost done with my game now (Yay!), and so I have to tackle all things that have been left over till now.
1) I use this
void DisplayText(String text)
{
lblMessage.Text = text;
gMessage.Visible = true;
int time_to_wait = Game.TextReadingSpeed * text.Length;
WaitMouseKey(time_to_wait);
gMessage.Visible = false;
}
for my text. Now there are some lines that are too long, that I need to append. I found an example in the manual,
String mytext = "Hello";
mytext = mytext.Append("World");
Display(mytext);
but I don´t knwo how I would apply it to "DisplayText"".
2) I want the description of a hotspot to change after looking at it. I found this
if (Hotspot.GetAtScreenXY(mouse.x, mouse.y) ==hotspot[1] && bool==false) // bool is the bool name you gave it and use its hotspot i.d. and even add the players room so it only applies in that room (if global.)
// Describe as this
else
// Describe as this
posted by Slasher in another thread. But how does "Describe as this" work? Do I make a new Text GUI for it?
3) When I have an item selected in the inventory window I would like to deselect it by right mouse click like it does outside the inventory.
And also is there an easy way to prevent the mouse cursor going to "Look" whenever items are combined?
4) I use this script by Khris to make the Audio play continously
AudioChannel *bgm;
void SetBGM(AudioClip *music) {
if (bgm == null || bgm.PlayingClip != music) bgm = music.Play();
}
and if possible I would like to reduce the volume, when you enter a building. I found this
AudioChannel* chan = aExplosion.Play();
chan.Volume = 20;
but how can I use it without making the clip play again?
If made it through to this, thank you a lot for reading all that stuff!
1) Isn't this working?
String mytext = "Hello";
mytext = mytext.Append("World");
DisplayText(mytext);
2) You don't need a new gui for this but you'll change the text of the label you already got for the hotspot names. You might want to check out my answer in this thread (https://www.adventuregamestudio.co.uk/forums/index.php?topic=57540.msg636612135#msg636612135) (there, instead of a variable I check the object's changed graphic).
3) You'll need to check eMouseRightInv in the on_mouse_click function.
if (button == eMouseRightInv) player.ActiveInventory = null;
1) Call DisplayText() two times or make the label bigger in the GUI editor.
2) If you mean the short text that appears when you hover the mouse over the hotspot, that's unfortunately not that easy to accomplish. The property is Hotspot.Name, and it's read-only. Slasher was talking about an actual description, i.e. something the player character says about the hotspot.
A common workaround for changing the read-only description is what Matti links to, i.e. directly change the label's text from @OVERHOTSPOT@ to a custom name. This requires repeatedly_execute code in the global script though.
4) you can simply do
bgm.Volume = 20;
Since you'll probably be doing this from a room script, you need to make the variable global first though.
Directly after AudioChannel *bgm; add the line:
export bgm;
In the global header, add
import AudioChannel *bgm;
1) Oh man, my label was wider than the game width and I just needed to change that. So that was easy to solve :-[
2) Okay, I read a bit about what Matti wrote in the other thread and I think I might not be able to do that. I will take the easy solution here and just let the character describe it with DisplayText. Thanks for the idea though!
3)I tried to put Mattis code in mouse_on_click, but it did not change anything.
4)Thank you Khris! That is so easy to use.
2) Why not? It's not that hard, just annoying to script.
3) To be precise, you need to turn on custom inv click handling in the General settings, and you'll want something like
// after eMouseRight block
else if (button == eMouseLeftInv) {
InventoryItem *ia = inventory[game.inv_activated];
if (mouse.Mode == eModeInteract && player.ActiveInventory == null) player.ActiveInventory = ia;
else ia.RunInteraction(mouse.Mode);
}
else if (button == eMouseRightInv) {
if (player.ActiveInventory != null) player.ActiveInventory = null;
else inventory[game.inv_activated].RunInteraction(eModeLookat);
}
2) I don´t really understand the scripting. I tried to make it work somehow by putting
lblDescription.Text = Game.GetLocationName(mouse.x, mouse.y);
in Rep.ex. in the global script and
if (lblDescription.Text == hMaat.Name && MaatLooked==true) lblDescription.Text = "Maat";
in the Rep.ex. room script, but it does not work. Before I make my next game I will watch some more basic scripting videos on youtube, but I think for this one I need to keep it really simple :D
3) Hm, I tried to use your code after enabling custom inv click handling, but now I can not pick up item from the inventory anymore nor look at them.
Put both lines in the global script like this:
lblDescription.Text = Game.GetLocationName(mouse.x, mouse.y);
if (lblDescription.Text == hMaat.Name && MaatLooked==true) lblDescription.Text = "Maat";
Just for clarification:
The first line makes sure that the label called "lblDescription" shows the name of the location the mouse is hovering over.
The second line changes the name of the specific hotspot hMaat to "Maat" in case the bool MaatLooked is set to true.
(EDIT: to be precise: it doesn't change the name, but it changes what the label displays)
Please always say what exactly doesn't work, so it's easier to find the solution.
Sorry, I thought it would not work at all because I tried to make the label in a Gui like the Displaytext Gui, well it was a mess.
But now that I just put hte new label in the statusline, the Hotspot Descriptions show up just fine. But I can not put
if (lblDescription.Text == hMaat.Name && MaatLooked==true) lblDescription.Text = "Maat";
in the global script, because it says GlobalScript.asc(61): Error (line 61): undefined symbol 'hMaat'.
Right, sorry. Of course you have to put it in the room's script (roll).
Glad it works now.
Well the bad thing is, it does not work :-D
It still does not change the description into anything else after the bool turns true.
I even tried abother approach like this
if (Hotspot.GetAtScreenXY(237, 172) ==hotspot[26]) {lblDescription.Text = "Maat"; }
to see if it would turn out any different, but it does not.
My idea is, that maybe lblDescription.Text = Game.GetLocationName(mouse.x, mouse.y); can not be overriden. But I don´t know.
That's weird, this should definitely work.
Are you really sure that MaatLooked is true? Just could check by putting this in the room's rep exe:
if (MaatLooked) lblDescription.Text = "true";
Add the RepExec event and function to the room.
Then put this inside the function:
if (Hotspot.GetAtScreenXY(mouse.x, mouse.y) == hMaat && MaatLooked) lblDescription.Text = "Maat";
As for the inventory code, I assume you're using two-click handling? My code should enable you to pick up items by clicking them with eModeInteract, but I'm just guessing here. Are you using the BASS template?
I did all that, but it still just shows the usual description. The bool was true, I checked that with DisplayText, because this if (MaatLooked) lblDescription.Text = "true";
would not work either. I don´t know if its even worth the effort at this point, but thanks for putting up with me.
I use the Sierra Style template. By two click you mean left for ineract and right for look?
for 2) there's also the alternative of using custom properties, use a String and type the description in there, point the "label" to read from it, and then change the custom property at will.
this way you avoid having to create extra ifs and checks.
@Racoon, are you sure this lblDescription.Text is not set anywhere else in code?
The Sierra template? Yet you said
Quote from: Racoon on Mon 20/04/2020 10:05:39
3) When I have an item selected in the inventory window I would like to deselect it by right mouse click like it does outside the inventory.
That's not how the Sierra template works afaik. Right-clicking outside the inventory should change the cursor mode to eModeWalkto.
Yes, sounds more like you're using the BASS template. Check the header of GlobalScript.
I can´t find any clue in the header of the Global script. But I think I am using Sierra style. I disabled eModeWalkto because its a first person escape room game. So it changes into "Look" and does not actually deselect the piece and I just interpreted that as deselecting because I never went through all modes to see the item again. Sorry, that my description was misleading!
And I will try one more time to gel the label to work like I want to, but then I will just leave it as it is. I think it will be ok even without it.
If you're using the Sierra template, you can try this:
else if (button == eMouseLeftInv) {
// interact with item to grab it
if (mouse.Mode == eModeInteract) player.ActiveInventory = inventory[game.inv_activated];
// else process click
else inventory[game.inv_activated].RunInteraction(mouse.Mode);
}
else if (button == eMouseRightInv) on_mouse_click(eMouseRight); // redirect to standard right click
I tried your code, but it if I add it after the eMouseRight section,then I can not pick up or look at ineventoryitems. If I put the code to the beginning of the on_mouse_click function, it works so far, that I can pick up an item and look at it again, but it still does not change with right click. I also double checked that I put Override built in inventory window click handling to true.
Besides a proper sequence of if ... else if ... else if ... [...] ... else, it shouldn't matter whether you put that code at the start or near the bottom, which suggests that there's a brackets / nesting issue.
For instance if you accidentally put my code inside the eMouseRight block, it will never get called at all.
Can you post the full on_mouse_click you're using?
This is what it looks like if I put it where I think you meant for me to put it:
function on_mouse_click(MouseButton button) {
// called when a mouse button is clicked. button is either LEFT or RIGHT
if (IsGamePaused() == 1) {
// Game is paused, so do nothing (ie. don't allow mouse click)
}
else if (button == eMouseLeft) {
Room.ProcessClick(mouse.x, mouse.y, mouse.Mode );
}
else if (button == eMouseRight || button == eMouseWheelSouth){
// right-click our mouse-wheel down, so cycle cursor
mouse.SelectNextMode();
}
else if (button == eMouseLeftInv) {
// interact with item to grab it
if (mouse.Mode == eModeInteract) player.ActiveInventory = inventory[game.inv_activated];
// else process click
else inventory[game.inv_activated].RunInteraction(mouse.Mode);
}
else if (button == eMouseRightInv) on_mouse_click(eMouseRight); // redirect to standard right click
else if (button == eMouseMiddle) {
// Middle-button-click, default make character walk to clicked area (a little shortcut)
// Could have been just "player.Walk(mouse.x,mouse.y)", but it's best to
// leave our options open - what if you have a special script triggered
// on "walking" mode?
Room.ProcessClick(mouse.x, mouse.y, eModeWalkto);
}
else if (button == eMouseWheelNorth) {
// Mouse-wheel up, cycle cursors
// If mode isn't WALK, set the previous mode (notice usage of numbers instead
// of eNums, when it suits us)...
if (mouse.Mode>0) mouse.Mode=mouse.Mode-1;
else
{
// ...but if it is WALK mode...
if (player.ActiveInventory!=null)
{
//...and the player has a selected inventory item, set mouse mode to UseInv.
mouse.Mode=eModeUseinv;
}
else
{
// If they don't, however, just set it to mode TALK (change this line if you add more cursor modes)
mouse.Mode=eModeTalkto;
}
}
}
}
I almost got it solved now, but I mght need a bit help for the rest.
if (button == eMouseLeftInv) {
// interact with item to grab it
if (mouse.Mode == eModeInteract) player.ActiveInventory = inventory[game.inv_activated];
// else process click
else inventory[game.inv_activated].RunInteraction(mouse.Mode);
}
else if (button == eMouseRightInv)
{mouse.Mode = eModeInteract;
mouse.UseModeGraphic(eModePointer);}
Now I can select items in the inventory and deselect them, but only if I right click on an inventory item. So I think eMouseRightInv only gets called when the mouse is on an inventory item. What I want though is to deselect a picked item everywhere while the inventory is open.
I tried something like this, but it does nothing :(
else if (button == eMouseRight || button == eMouseWheelSouth){
  // right-click our mouse-wheel down, so cycle cursor
  if (gInventory.Visible==true){mouse.Mode = eModeInteract;
mouse.UseModeGraphic(eModePointer);}
  else mouse.SelectNextMode();
Quote from: Racoon on Sat 25/04/2020 12:43:53
Now I can select items in the inventory and deselect them, BUT only if I right click on an other inventory item. So I think eMouseRightInv only gets called when the mouse is on an inventory item. What I want though is to deselect a picked item everywhere while the inventory is open.
Ah, yes, I was confused by this too and solved it by putting this in the global script's on_event function:
if (event == eEventGUIMouseDown && mouse.IsButtonDown(eMouseRight) && player.ActiveInventory != null && data == gInventory.ID)
{
InventoryItem *ii = InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
if (ii == null)
{
player.ActiveInventory = null; // lose active inv
mouse.Mode = eModeInteract;
}
}
(replace gInventory in case your GUI is called something else)
I'm not at all sure if this is the most elegant way and I think scripting inventory stuff in AGS is a bit complicated. But it works :)
It finally works!! Thank you so much Matti! (I actually felt like shouting "Heureka" when I saw it worked)
And for the unlikely case someone finds the thread while searching for similar problmes. While looking up on_event I also found a working code for another question I had
QuoteAnd also is there an easy way to prevent the mouse cursor going to "Look" whenever items are combined?
function on_event(int event, int data)
{
{
if (event == eEventLoseInventory) { //loseInventory
if ((gInventory.Visible==true) && (mouse.Mode == eModeLookat)){
Mouse.Mode=eModeInteract;}
}
}
}
You're welcome, I'm glad it works :)
@Cassiebsg, I just tried the "Use a GUI as a Room-Darkening" technique. I was looking to use your method, but I found some issues with it, but it could work in a pinch on a small, easy screen.
First, I couldn't change the background color of the GUI to be "black" as AGS will use "(0 for transparent)". I did play with using just a dark gray color and changing the Transparency property to be 60 and that worked well enough.
But my background has some windows on it, and I wanted to let some "light shine through". So I instead changed from using a GUI background color, to a duplicated background image of my room, but with the window pane areas "cut out" (alpha) and the rest a 60% black covering. That looked like it would work out but then I hit another snag. My room is a scrolling room and the GUI doesn't scroll along with the character walking. I then get a ghostly shadow of my window panes floating as I walk the character off from the starting view.
I'll probably just switch to an animated background and use SetBackgroundFrame... but then that will fail to darken any of my animated objects in the room. Hmm...
Quote from: Scummbuddy on Fri 01/05/2020 00:54:19
But my background has some windows on it, and I wanted to let some "light shine through". So I instead changed from using a GUI background color, to a duplicated background image of my room, but with the window pane areas "cut out" (alpha) and the rest a 60% black covering. That looked like it would work out but then I hit another snag. My room is a scrolling room and the GUI doesn't scroll along with the character walking. I then get a ghostly shadow of my window panes floating as I walk the character off from the starting view.
If there are light and dark areas in the room, and room is scrolling, you could make a big room-size object, with varying sprite translucency.
Or, you could make a room-sized GUI with varying translucency (again using a sprite).
Quote from: Scummbuddy on Fri 01/05/2020 00:54:19
I'll probably just switch to an animated background and use SetBackgroundFrame... but then that will fail to darken any of my animated objects in the room. Hmm...
In this case, you could try setting LightLevel or Tint for characters and objects, it should be easy enough to do in a loop.
Actually you may even achieve dynamic lighting change by checking where a character is (on a light spot or dark spot) in rep_exec.