Using Global Script to set Background Frames

Started by reismahnic, Mon 18/01/2016 00:31:33

Previous topic - Next topic

reismahnic

Hello, I am working on a point and click adventure game in which I am swapping backgrounds, with five different backgrounds (realities) for each room.
When the player moves to a different room, I want the 'reality' they are in to carry over to the next room.
This could easily be done by scripting a background change in the GLOBAL script (every room now uses background 2, 3, etc), but the Global script doesn't seem to work with SetBackgroundFrame(1) or (2) etc.
Does anyone know how I could alter background frames in the Global Script, thus changing the default background frame in every room when they enter?
Sorry if I worded this weird. Thanks!

Kumpel

#1
Afaik there is no way to directly manipulate the background frame outside of a room script.

But you could set an global int variable f.e. "SetBG" and change its value in global script (or anywhere else) and let the game set it always with "SetBackgroundFrame(SetBG); in every room's repeatedly_execute_always function thus setting the background frame in real time.


:-[

Khris

In which function in the global script did you put the commands? "doesn't seem to work" is a completely useless problem description.

Anyway, what you do is use the on_event function:

Code: ags
function on_event (EventType event, int data) {
  if (event == eEventEnterRoomBeforeFadein) {
    if (data > 1) {
      SetBackgroundFrame(theReality);
    }
  }
}

This will change the background for rooms 2 and above.

reismahnic

#3
Hi Khris, sorry for being vague.

Currently I have the 'AR Vision', as it's currently called, set as an inventory item. I'm only using two backgrounds for this current example (to simplify things).
I have it set so that when you use the inventory item, it calls a global bool called ARIsOn, and that determines the background change.

Here's the code in the Global Script:
Code: ags

function iARVision_Interact()
{
if(ARisOn==true)
{
ARisOn=false;
player.ChangeView(4);
SetBackgroundFrame(0);

}
else
{
ARisOn=true;
player.ChangeView(5);
SetBackgroundFrame(1);
}
}

Currently, the 'SetBackgroundFrame' command doesn't in fact do anything. Changing the player's view, of course, does work.


I'm afraid I'm not sure where the on_event function is located? Where do I access this?
Thank you so much for replying. :)

Crimson Wizard

#4
Just to clarify: it has close to ZERO difference, what script are you calling a function from (note, I am speaking about globally defined functions, not local symbols you declare in room script).
If you use room functions, from global script, or custom script, these function will simply refer to current loaded room.

The only place where you should not use room-related functions, is "game_start" function, because at that point first room is not loaded yet.

If the room function is not working, probably script is incorrect, or room does not own an item you are referring to (e.g. background of particular number).

Khris

on_event() is simply added to GlobalScript.asc, where ever you like, but of course outside any existing functions.

Are you using the default template? Because if so, how are you triggering the function? Clicking an inventory item will select it, not interact with it.
In other words, which in-game action is supposed to make AGS call the function?

There's a ChangeView() command in there. Does that get called? If not, that indicates that the entire function is never even run in the first place.

Also, try and use indentation:
Code: ags
function iARVision_Interact()
{
  ARisOn = !ARisOn;  // toggle value
  if (ARisOn)
  {
    player.ChangeView(5);
    SetBackgroundFrame(1);
  }
  else
  {
    player.ChangeView(4);
    SetBackgroundFrame(0);
  }
}

Monsieur OUXX

On a different note, I'd like to say that I hate using background frames, because they use up a lot of memory usually for just a small animation somewhere in the background, and they often mess up additional modules that didn't take them in account. Not trying to discourage you from using them (if it fits, it fits) -- just saying.
 

SMF spam blocked by CleanTalk