A simple message has got me stumped

Need help with using DizzyAGE then look here
Post Reply
Grandad
Hard Boiled Egg
Posts: 1488
Joined: Sat Aug 08, 2009 10:47 am
Location: Balham - gateway to the south

A simple message has got me stumped

Post by Grandad » Wed Sep 23, 2009 2:59 pm

I've no idea what I'm doing wrong. In the demo game I'm testing switching to a new location when exiting a room rather than going to the adjacent room. The code worked fine ...until I tried to include a message on arrival. The message displays but MessagePop won't clear it and the game locks. I've tried putting the message in different parts of the code, but then either I get loading errors or the message also appears when I enter the 'teleported' room normally ..and locks! Could some kind soul tell me how I've screwed up what seems like a very simple bit of coding. Thanks

//moving to new location when exiting room
func OutRoom_2_1()
{
x = PlayerGet(P_ X) ;
y = PlayerGet(P_Y);

If (x<495) //x axis of the edge of the room being exited
{
x = 779;
y = 247;
PlayerSet(P_X,x);
PlayerSet(P_Y,y);
Message1 (14,6,”WHERE AM I?&#8221 ;) ;
MessagePop();
}
}

Grandad
Hard Boiled Egg
Posts: 1488
Joined: Sat Aug 08, 2009 10:47 am
Location: Balham - gateway to the south

Post by Grandad » Wed Sep 23, 2009 3:02 pm

Err, I don't know why the smilie appears in the posting ...but please consider it as an X.

Grandad

delta
Hard Boiled Egg
Posts: 3965
Joined: Fri Feb 09, 2007 7:08 pm
Location: North West
Contact:

Post by delta » Wed Sep 23, 2009 3:19 pm

You're trying to call a message from a function that updates the room. The problem with that is that you're trying to perform a latent function from a non-latent area of the code.

Basically, you can't perform actions that need player input (such as calling messages etc) in functions that could be called every frame (such as UpdateRoom, OutRoom, etc).

A better way to do it would be to put a collider just at the exit of the room, that dizzy will collide with before he exits. If you put your code in the CollideObject code for that object, you should get your intended result.

also, the X) smiley that you got is because you put X and ) together, so the forums see it as a smiley. it's best when pasting code into the forums, to use the CODE and /CODE wraparounds (quote this message to see what i mean) to create a box to put your code into:

Code: Select all

code goes here
as shown above. :)
Image

Image

"Quotes from the internet may not be genuine" - Abraham Lincoln

Grandad
Hard Boiled Egg
Posts: 1488
Joined: Sat Aug 08, 2009 10:47 am
Location: Balham - gateway to the south

Post by Grandad » Thu Sep 24, 2009 9:48 am

D'oh! Thanks Jamie ..told you I was an absolute beginner and thought that RoomOutput was the best place to put a 'switch room' command. Still, best to learn from silly mistakes to fix parts of the game logic in the old grey matter. So now I've learnt that I can 'teleport' with a RoomOutput command providing I don't add any player input ...or use the collideObject code to do the same thing with messages.It's also helped with something else that I wanted to do, which is having messages appear when 'dropping' as I can just put colliders in the room to bring up the messages.

Thanks again

Grandad

Code: Select all

Ah, got it!

delta
Hard Boiled Egg
Posts: 3965
Joined: Fri Feb 09, 2007 7:08 pm
Location: North West
Contact:

Post by delta » Thu Sep 24, 2009 7:31 pm

don't worry about it! i think we've all made that mistake at some point or other :)
Image

Image

"Quotes from the internet may not be genuine" - Abraham Lincoln

xelanoimis
Team Yolkfolk
Team Yolkfolk
Posts: 1014
Joined: Sun Jan 21, 2007 6:34 pm
Contact:

Post by xelanoimis » Sun Sep 27, 2009 10:11 am

From a non-latent function you can request a latent function (which will be started on the next frame) with ScrRequest and the id of the function, obtained with gs_fid. Look for these commands in the documentation index and check the handlers.gs script to see how they are used.

This is useful in the OpenRoom callback (which is not latent in the default template - is simply called from HandlerRoomOpen). In OpenRoom_RX_RY you can request a latent function where you can call the message function.

The latent function will run if no other latent function is already running. If needed, you can force the current latent function to stop, but usually this is not needed.

Also consider that a collision latent response will not be executed if another latent function is running.

In your case, the game was "freezing" because the message function pauses the game and shows the text dialog. And because it was called from non-latent code it was exiting at this point, leaving the game paused. When called from a latent code, the execution would be continued on the next frame and the message will stay on screen until user presses key. Then the dialog is closed, the game is resumed and the latent message function ends. See messages.gs for details.

Alex

delta
Hard Boiled Egg
Posts: 3965
Joined: Fri Feb 09, 2007 7:08 pm
Location: North West
Contact:

Post by delta » Sun Sep 27, 2009 9:41 pm

aha, we learn something new everyday! :)
Image

Image

"Quotes from the internet may not be genuine" - Abraham Lincoln

Grandad
Hard Boiled Egg
Posts: 1488
Joined: Sat Aug 08, 2009 10:47 am
Location: Balham - gateway to the south

Post by Grandad » Tue Sep 29, 2009 11:48 am

Thanks Alex, much appreciated. Collide Objects are also very useful for what I'm trying to achieve in my game ...and thanks again to you Jamie as I have discovered your wonderful 'enable' and 'disable' blocker code in the util file of Illusion Island ...after a whole weekend of pulling apart the map of Mushroom Pie and trying to relate it to the code in an attempt to figure out how to set the trigger to disable a block and then in a last minute act of frustration, unpacking Illusion Island to look at how you dealt with the boulders with the 'cheap' pickaxe to see if that would help.

Slowly, but hopefully surely, things are dropping into place ..and I've now managed to get a van to appear and move across the screen and park when the player changes a 'no parking' sign to a 'parking' sign (by using a pot of paint over the 'no'!). You won't believe how chuffed I was when I first got that to work!! Unfortunately I've now got to rewrite that bit of code as the player can still move across the gap whilst the van is moving as the useobject code disables the block. I don't want to set a status as there is no real reason for the player to try and action the sign again after the van has parked, nor can I set the disable in the roomupdate that gets the van moving as it just disables the block when you enter the room for the first time. Hmm have just wondered whether I can pause the player whilst the van is moving. Oh well, back to the well thumbed DizzyAGE book.

Grandad

Grandad
Hard Boiled Egg
Posts: 1488
Joined: Sat Aug 08, 2009 10:47 am
Location: Balham - gateway to the south

Post by Grandad » Tue Sep 29, 2009 1:41 pm

Couldn't seem to find anything in the book about pausing the player, but have solved it in a different way. Added an extra message to make the player run away and repositioned them in the previous room. Then set the speed of the waypoint a bit faster so that when they re-entered the room the van started moving and as they had further to walk the player reached the waypoint just after the van stopped (more by luck than judgement). Probably not the best solution, but it worked. :v2_dizzy_thumbsup:

Grandad

delta
Hard Boiled Egg
Posts: 3965
Joined: Fri Feb 09, 2007 7:08 pm
Location: North West
Contact:

Post by delta » Tue Sep 29, 2009 2:34 pm

use PlayerEnterScripted(); to stop the player moving, and PlayerEnterIdle() to start the player moving again.

be careful when using it though, as if you have custom movement code, it may clash with that.

or alternatively, WaitTime(x); (with x as the number of seconds to wait), or WaitFrames(x); (with x as the number of frames to wait), should also work. These are both latent however, so don't use them in room update functions!
Image

Image

"Quotes from the internet may not be genuine" - Abraham Lincoln

Post Reply