Page 1 of 1

Dynamic Stairs question

Posted: Sun Dec 12, 2010 12:40 am
by Robbington
Hey,

Have just come across DizzyAge and have started to create my own fan game. Have two questions if thats ok.

1st, I would like to have stairs that raise out of the floor when an action is triggered. I've got this far:
func UpdateRoom_1_9() { step1(); step2(); step3(); step4(); step5(); }

func step1()
{

idx = ObjFind(4100);
if(!IsUpdate(ObjGet(idx,O_DELAY))) return;

y = ObjGet(idx,O_Y);
if(ObjGet(idx,O_STATUS)==1)
{
y -= 1;
if(y<=1327)
{
y=1327;
ObjSet(idx,O_STATUS,0);
}
}
ObjSet(idx,O_Y,y);

}
But obviously updateroom() isnt triggered so it just happens at the start of the game.
Second:
Am trying to get it so a triggerd action sends Dizzy to another room.
func ActionObject_2003()
{

OutRoom_1_7( );
}

func OutRoom_1_7()
{
ScrRequest(gs_fid("OpenRoomLatent_1_7"));
}

I guess what I am struggerling is how to call these functions by trigger.
I'm guessing I am going about it all wrong so a poke in the right direction with a pointy stick would be great.

Rob

Posted: Sun Dec 12, 2010 1:56 am
by delta
Hi Rob, welcome to the community!

This will be a brief reply, as it is late, and typing on phones isn't conductive to detailed responses.

First query, I see nothing immediately wrong with the bulk of the code, you just need something in an ActionObject function to trigger it (changing and checking the STATUS property).

Second query, yes unfortunately is completely wrong. OutRoom is a function called when exiting a room, to deal with things other than player position. I think for your purpose you need PlayerSetPos(X,Y); which hopefully is self-explanatory.

I will expand on those brief answers in the morning, while sat in front of a proper keyboard, and with a fully-functional brain. :)

Posted: Sun Dec 12, 2010 8:47 am
by Lex_Hedley
Welcome Rob,

When I first started I downloaded all the help files from

http://www.yolkfolk.com/dizzyage/books/gs9/page00.html

http://www.yolkfolk.com/dizzyage/books/ ... age00.html

http://www.yolkfolk.com/dizzyage/books/ ... 0_toc.html

which are a great resource, as well of course this forum

For your first problem there is
http://www.yolkfolk.com/dizzyage/books/ ... ction.html
to get you started

Secondly
<table class="solid_yellow"><tbody><tr class="solid_yellow"><td class="solid_amber" colspan="4">PlayerSetPos( x, y )</td> </tr> <tr class="solid_yellow"><td class="solid_green" width="30px">IN</td><td class="solid_yellow" width="40px">int</td><td class="solid_yellow" width="40px">x</td><td class="doc">horizontal coordinate in world</td></tr> <tr class="solid_yellow"><td class="solid_green" width="30px">IN</td><td class="solid_yellow" width="40px">int</td><td class="solid_yellow" width="40px">y</td><td class="doc">vertical coordinate in world</td></tr> </tbody></table> Set player's position

Hope this points you in the right direction

Alex

Posted: Sun Dec 12, 2010 10:41 am
by Robbington
Thanks for the speedy response guys,

I have been a big fan of the Dizzy games since I was a kid so was quite excited to come across the engine.

Genius, I have fixed the two problems now. Thanks so much, as you said just needed to change the status. I was being a bit dense last night and had my objects status at 1.... Changed it to 0 and set it to change when the action was triggered.

As for the other prob, was just getting a bit confused by this line in the game.gs
"
OutRoom_RX_RY() - called by HandlerRoomOut when player wants to exit room RX,RY (can reposition player here) (non-latent)
"

Using PlayerSetPos works beautifully. If its not to much trouble, I was wondering how to set a delay on the action? if I can do it by frames or seconds?

I have four stairs that come out of the floor and a bit of the roof that comes down, I would like it so the roof come down only when the last stair is in position. I have tried adding the status change at the end of the final stair if loop, but this doesnt seem to work.

I was also going to start a thread and post working code segments with comment so that other people can use them. Best place?

Rob :)

Posted: Sun Dec 12, 2010 11:15 am
by Robbington
Sorry, I should have been more specific,

The problem isnt that it doesnt work, its when the final step gets to its y pos the bit of roof doesnt just sink down it appears at it's y location. Here is what I have done.
// Last step
func step4() {
idx = ObjFind(4103);
if(!IsUpdate(ObjGet(idx,O_DELAY))) return;

y = ObjGet(idx,O_Y);
if(ObjGet(idx,O_STATUS)==1)
{
y -= 1;
if(y<=1269)
{
y=1269;
ObjSet(idx,O_STATUS,0);
}
if(ObjGet(idx,O_STATUS)==0)
{
idx = ObjFind(4104); // id of roof bit
ObjSet(idx,O_STATUS,1);
}
}
ObjSet(idx,O_Y,y);
}

Posted: Sun Dec 12, 2010 11:45 am
by delta
Robbington wrote:"
OutRoom_RX_RY() - called by HandlerRoomOut when player wants to exit room RX,RY (can reposition player here) (non-latent)
"
this is automatically called by the game engine when Dizzy exits a room (if you've added that code). It's similar to CloseRoom, except CloseRoom works just after you exit, whereas OutRoom works just before you exit. The idea is that if you don't want the player to exit just yet, you can stop him before he does.
Robbington wrote:Using PlayerSetPos works beautifully. If its not to much trouble, I was wondering how to set a delay on the action? if I can do it by frames or seconds?
use WaitTime(T); (where T is the time in seconds) or WaitFrames(F); (where F is the time in frames - there's approx 36/37 frames per second). Bear in mind however that you won't be able to do anything while you're waiting.
Robbington wrote:I was also going to start a thread and post working code segments with comment so that other people can use them. Best place?
hmmm there isn't a place really. What tends to happen is that people will look at the code in your game once it's released if they're curious about how you've done something. Failing that, they'll ask on the forums how to do something.

You can create a thread in the 'DizzyAGE Help' forum for it all, but I'm unsure of how much use it will be to others. It's rather rare that a section of code can be used for exactly the same thing in more than one game (especially someone elses, as they'll usually have a different way of coding), unless you've specifically wrote the code to be flexible in that way. *shrugs*

Posted: Sun Dec 12, 2010 11:54 am
by delta
Robbington wrote:Sorry, I should have been more specific,

The problem isnt that it doesnt work, its when the final step gets to its y pos the bit of roof doesnt just sink down it appears at it's y location. Here is what I have done.

Code: Select all

// Last step
func step4() {
	idx = ObjFind(4103);
	if(!IsUpdate(ObjGet(idx,O_DELAY))) return;

	y = ObjGet(idx,O_Y);
	if(ObjGet(idx,O_STATUS)==1)
	{
		y -= 1;
		if(y<=1269)
		{
			y=1269;
			ObjSet(idx,O_STATUS,0);			
		}
		if(ObjGet(idx,O_STATUS)==0)
		{
			idx = ObjFind(4104); // id of roof bit
			ObjSet(idx,O_STATUS,1);
		}
	}
	ObjSet(idx,O_Y,y);
}
Right, one reason it may not be working is because you also define idx as the 'roof bit' (obj 4104), and then go on to change the y position of obj idx using ObjSet(idx,O_Y,y); - hence the code is changing the wrong object when the Status is changed to 1.

in the code below, the blue highlighted section changes the variable used (from idx to roof) to fix the confusion. Also, I've highlighted in Red code that isn't needed (you just changed the status of that object, so if you keep the code within the same if statement, you don't then need to check that it's been changed)

Also, I've added the line highlighted in green. This will ensure that if the object is offscreen before it is moved, it is drawn in the current screen (if it's moved to the current screen). Without that line, it can be hit-and-miss whether it is or not.

Code: Select all

// Last step
func step4()
{
	idx = ObjFind(4103);
	if(!IsUpdate(ObjGet(idx,O_DELAY))) return;

	y = ObjGet(idx,O_Y);
	if(ObjGet(idx,O_STATUS)==1)
	{
		y -= 1;
		if(y<=1269)
		{
			y=1269;
			ObjSet(idx,O_STATUS,0);[color="Red"]			
		}
		if(ObjGet(idx,O_STATUS)==0)
		{[/color]
			[color="DeepSkyBlue"]roof[/color] = ObjFind(4104); // id of roof bit
			ObjSet([color="#00bfff"]roof[/color],O_STATUS,1);
		}
	}
	ObjSet(idx,O_Y,y);
	[color="SeaGreen"]ObjPresent(idx);[/color]
}
I hope that solves things for you! :)

Posted: Sun Dec 12, 2010 12:11 pm
by Robbington
Thanks that worked a treat.

I was thinking more of the posts as small tutorials really.

For instance the stairs coming up from the floor, although its specific to my game, its a nice feature that could be incorperated into any game and with a little tweaking can be used in a few ways.

But if you think its not really worth it I will just let people scrutinize my dodgy code from source. :P

Thanks again for the help.

Rob

Posted: Sun Dec 12, 2010 12:19 pm
by delta
I think the main problem with doing it in the forums is that the code will quickly get lost amongst the dozens of pages in dozens of other threads in this forum.

There are tonnes of bits of code dotted around in this forum from people helping others out, but the problem is finding that specific bit when someone needs it! So sometimes code for doing something has been shown twice, or even three times, simply because people either haven't realised it's been done before, or they couldn't find it.

I've nothing against someone doing it, I'm just not sure that a forum is the best place for such a repository. Have a look through the dozens of pages in the 'General Coding Queries' thread to see what I mean about how easy it is for code to get lost. :v2_dizzy_smile:

Posted: Sun Dec 12, 2010 12:32 pm
by Robbington
Ok thanks,

The WaitTime function worked great as I mentioned before, but its very helpful to see where I was going wrong.


Rob