Bus arriving on cue

Started by georgeh, Tue 24/02/2015 21:02:22

Previous topic - Next topic

georgeh

Hello to everybody.This is my first post and very thrilled about it.A question about where to put my script.I have my character finding a ticket and i want after this a bus arriving to pick him up.I have done the scripting and its working with sound and everything but i have put the whole function after room_fadein.For this to work i have to leave the room and come back again.I have tried putting it in the GlobalScript but i get an error.It doesnt recognise my "obus" object.Where should i put this script to run on cue?

Cassiebsg

Hi and welcome.

You can script it on the GlobalScript, but instead of using the object name you need to use it's ID.

So let's say your obus ID is 1:

replace obus with object[1]

Simple as that. Good luck!
There are those who believe that life here began out there...

georgeh

Thank you for the quick reply.I have done that but now nothing is working since i get a lot of errors in GlobalScript.Something (or everything) needs to be changed.
Here is my original script:
function room_AfterFadeIn()
{

if ((cego.ActiveInventory == icutticket) && (cego.Room == 4)){
  obus.Visible=true;
  aBusarrive.Play();//play engine sound//
  obus.Move(60, 450, 2, eBlock, eAnywhere);
  aBusidle.Play(0, eRepeat);//play engine sound//
If i put it in G.S nothing is working.How can i modify it to run the moment my character finds the ticket?
Forgive my ignorance.
}

Mandle

G'day...

You need to use THIS <----(Click here for link to manual)

The manual explains more in depth and clearer than I could here.

Best of luck!

georgeh

Thank you for pointing that to me.I assumed that repexec was for something to happen all the time ,not once.I am learning by reading tutorials and then return to the manual for further explanation.
Sorry for the trouble.
Good day to you too.:-D

HAL

#5
I had a similar problem in the game I just made. It also involved RepExec, and I absolutely couldn't make the event happen until I'd changed rooms.

My solution involved changing rooms and then changing back again instantaneously so it wasn't even noticeable.

However this is only possible if you set the room-change animation to instantaneous, instead of fade-in-fade-out.

My solution looked a bit like this:


In Global Variables create a bool with an apt name.
Let's call ours:
Code: ags

// Global Variables. (Not actually a script window. It's the Global Variables window. I presume you know what I mean).

bool AnnoyingNecessaryRoomChange = false;



Ok so you now have a bool, initialised as 'false', in the Global Variables window.

Now, onto the code.

Code: ags

  // in first room. 

function room_AfterFadeIn()
{

if ((cego.ActiveInventory == icutticket) && (cego.Room == 4)){     // so this the code that you say will only run once after a room change.
  obus.Visible=true;
  aBusarrive.Play();//play engine sound//
  obus.Move(60, 450, 2, eBlock, eAnywhere);
  aBusidle.Play(0, eRepeat);//play engine sound//

}
    // try adding this to the room script.
    //
    //
 
function The_function_where_your_character_finds_the_bus_ticket()
{
    cEgo.AddInventory(icutticket);
    AnnoyingNecessaryRoomChange = true;   
    SetNextScreenTransition(eTransitionInstant);
    player.ChangeRoom(2)
}



Code: ags

   // in Room 2 (actually you could change to pretty much any room. Change to a really basic, unimportant room without start-up events in. Just to be safe)

function Room_Load()
{
     if (AnnoyingNecessaryRoomChange == true){
         AnnoyingNecessaryRoomChange = false;
        SetNextScreenTransition(eTransitionInstant);
        player.ChangeRoom(4);
     }
}


This should flick you over to the other room, then instantly flick you back again so the animation will start.

The 'AnnoyingRoomChange' bool will be set to false after the event has happened, so you enter the other room normally after that.


Mandle

I can promise you that a room change is not necessary to have an event take place from RepExec(Always?), because I've made it happen before in a game I made (Speed Buggy) and it worked just fine. I forget now if I used RepExec or RepExecAlways (or whatever it's called) but as soon as the player completes a set of goals the game cuts instantly to a cutscene just as it should. I don't have the game code with me on this computer but I can look it up sometime for you if somebody wiser in coding doesn't come along first to clear this up.

HAL

Quote from: Mandle on Fri 27/02/2015 05:35:22
I can promise you that a room change is not necessary

Oh yeah I definitely agree with that.

I'm just explaining how I personally got round it.

I think my issue was that my game involved pretty much the entire thing going through RepExec in every room, so it was hard to single out where a problem may have been occurring.

Anyway, my workaround worked so...  :tongue: . Now go kill some space cats.

HandsFree

If you want the bus to arrive as soon as ceEo has the ticket there's no need for repexec.
How does cEgo acquire the ticket?
Can't you just write the code in the same place cEgo finds/gets the ticket, where you set the cEgo.ActiveInventory = icutticket? Probably ocutTicket_Interact() or something like that?

Or do I misunderstand the problem?

georgeh

Hello and thank you for your replies.Look,cego finds a ticket but its not the regular bus ticket.So he thinks if he can cut it,it would still pass as a regular bus ticket.So he finds a pair of scissors,cuts the ticket and produces a regular bus ticket.To do this i used iticket_UseInv() in the global script(and vice versa for the isciccors) and then produce a cutticket(icutticket).So i want when this happens (after a while,lets say 4 sec if possible(optional but more realistic)),the bus arrives.

HandsFree

#10
Ok, don't know if the true experts have a different idea, but I would do this:
In the room script, before the first function, put:
int bustimer = 0;

Then in the room's repexec:
Code: ags

function room_RepExec()
{
  if (cEgo.HasInventory(iCutticket) && bustimer < 160) bustimer++;
  if (bustimer == 160){
    //code for bus arriving
    bustimer++;
  }
}


edit: note that you do not need repexec to just check the condition. You could do that where you use the scissors on the ticket. But you do need repexec to allow 4 seconds to pass.

georgeh

Thanks everybody for your trouble.Well i took a different aproach.I placed a ticket validation machine by the busstop and after using the ticket,it "played" the script "busarrive" sequence.It was much easier for me.Anyways thank you all again for your trouble.

SMF spam blocked by CleanTalk