Non-clickable CCTV style overlay

Started by CCrane, Thu 17/11/2022 10:58:16

Previous topic - Next topic

CCrane

Hello,

depending on difficulty of solution this might be in the wrong section but maybe it's really easy to solve ... anyways, I'd like to have a CCTV camera style overlay for my game. The GUI should look like about this:

H9Vvx6X.md.jpg" border="0

I guess the static text I can solve with labels and for the health bar I should be fine with any of these.

https://www.adventuregamestudio.co.uk/forums/beginners-technical-questions/making-a-3-life-health-system-work-solved/
https://www.adventuregamestudio.co.uk/forums/beginners-technical-questions/how-to-make-a-life-bar/
https://www.adventuregamestudio.co.uk/forums/beginners-technical-questions/retain-health-bar-level/

What I don't know is how to update the time and I need to somehow read out the room name. The cam number should preferably change, too.

Is there some function/token I can use like @GAMENAME@ or @SCORE@ ? That would be awesome!

Thank you!


*I know the screen shows a night scene but the time can be just sytem time.

@ChristophCrane_ (Indie author)

Snarky

If you want to display the system time, you would use the DateTime API. The basic approach is to do it in repeatedly_execute(), grab DateTime.Now, and format the various fields into a String.

There is no way to get the room name. It isn't stored as a String once the game is compiled, just a number. You will have to do something like set up a String array with all the room names, and use the room number (player.Room) to look it up. You can also use the room number as the camera number if you like.

Khris

#2
Regarding the room names, you can use custom properties for this. Open a room, then look at the Properties window and find the Properties section. In there it says "Properties: (Properties)". Click the ellipses button, then "Edit schema...".
Right-click the empty table and add a new property.
Name: RoomName
Type: Text
Uncheck everything except "Rooms".
Click "OK", then "Close".

You can now enter "Main Hall" next to "RoomName" in the respective room properties, same for the other rooms.
Now add this in the GlobalScript:
Code: ags
function on_event(EventType event, int data) {
  if (event == eEventEnterRoomBeforeFadein) {
    lblRoomName.Text = Room.GetTextProperty("RoomName");
  }
}

This assumes that the label for the room name is called "lblRoomName".

edit: fixed event name

CCrane

Thanks for the answers so far, guys
 
I tried Khris' first and it worked in the first room perfectly but when I entered the second room the game crashed.  All I could tell was the label didn't show up or didn't show anything, FWIW.
 
  btw:
  EventBeforeFadein
  This happens to be: eEventEnterRoomBeforeFadein ?
 
Anyway, this was my function in GlobalScript that led (presumably) to the crash:
 
Code: ags
function on_event(EventType event, int data) {
  if (event==eEventLeaveRoom)
  if (event==eEventRestoreGame) {
    Verbs.Localize();
  }
  //last inserted
  if (event == eEventEnterRoomBeforeFadein) {
    lblRoomName.Text = Room.GetTextProperty("RoomName");
  }
  
  // commented out earlier
  //if (event==eEventEnterRoomBeforeFadein || event==eEventRestoreGame)
  //  player.PlaceOnWalkableArea();
}
 
I commented the new code out, then deleted the newly added property but it still crashed.
I have no crash dump file but I ran the game through terminal and these were the last lines:

Code: ags
<pre>Starting game
WARNING: channel 2 - same clip assigned
An internal error has occurred. Please note down the following information.
If the problem persists, contact the game author for support or post these details on the AGS Technical Forum.
(ACI version 3.5.1.22)

Error: prepare_script: error -18 (no such function in script) trying to run 'room_FirstLoad'  (Room 2)

***** ENGINE HAS SHUTDOWN
</pre>

I'm not so sure anymore if the crash got anything to do with Khris' code but my FirstLoad just looks like this. It's basically Tumbleweed related and I never touched it actually.

Code: ags
function room_FirstLoad()
{
  Doors.SetDoorState(10, 2);
  Doors.InitObject(10, oDoor.ID);
  cRadio.Baseline = 250;
}

I'm only at the beginning of my game so it's no big deal to start all over again instead of a bug hunt. What do you think?

@ChristophCrane_ (Indie author)

Khris

The error means that room 2 has no room_FirstLoad function. This happens when you remove a function from your room script that is still linked in an events pane.

Adding
Code: ags
function room_FirstLoad() {}
to your 2nd room's script should fix this.

(If the script at the bottom of your post is indeed room 2's, something else is happening, not sure what though)

CCrane

Just came back from some testing and can confirm now that Khris' method works fine.

Quote from: Khris on Thu 17/11/2022 14:14:07The error means that room 2 has no room_FirstLoad function.
Now that you say that I noticed already in room 1 that FirstLoad seems not to be executed either although it doesn't lead to the game crashing.

Quote from: Khris on Thu 17/11/2022 14:14:07This happens when you remove a function from your room script that is still linked in an events pane.
The strange thing is I didnt remove it from script but whatever. I'll comment it out, de-link it and move the function's commands to be activated by a region just as I already did in room 1.

Sorry for the inconvenience :confused:

@Snarky,
I'm going to test the timedate function a little later.

cheers

@ChristophCrane_ (Indie author)

Khris

This is a crucial mechanism of AGS, I definitely wouldn't introduce workarounds in room 2 of your game, especially not for basic functionality. You should learn how it works and implement it properly.

It's also really simple.

Any event like the game entering a room for the first time, the user clicking a hotspot with the interact cursor, the player walking off a region, etc. will make the engine look at the respective event table row for a function name. If the field is blank, nothing happens.
If the field isn't blank, AGS will try to call a function of that same name in the respective script. For room-specific stuff that's the room script, for events related to global stuff like inventory items, characters, GUI controls and the like it's the global script.

Initially, all event table fields are blank, and no event functions exist (except for a few standard engine ones in the global script, some of which do not need to be entered into a table). For any specific event, there's 3 other cases:

a) The function exists in the proper script, but the table entry is blank -> the function isn't linked to the event and therefore doesn't run. This is a very common beginner's problem and mostly happens when people paste functions from other scripts or from the forums.

b) There's a function name in the events table but no function of the same name in the script -> AGS crashes, telling you exactly what the problem is

c) the function exists in the correct script and its name is entered into the table -> everything works just fine


Again, this is very basic stuff, both in the sense of being the engine's backbone and the skill level required to understand it.

SMF spam blocked by CleanTalk