The Dink Network

could use some help with my script

July 7th 2010, 06:01 AM
peasantfr.gif
I just started to create my first D-mod. But am stuck on creating a script for a fence that can open and close.

I just posted the script as I made it. With explenation on why I did things (mainly to keep track of things myself).

If you enter the screen you can interact with the fence as intended, but when you leave and come back it goes wrong. if I closed the fences before leaving the screen, they are gone when I come back and if I opened them before leaving the screen, they show open when I come back but I can't talk to them anymore.

I tried giving them a brain 5 but then I can't talk to the fence after the first time opening it so that makes it just worse. The use of visions is not possible since dink is in the screen. I tried a lot of different things but nothing really works, it either screw up the hardness or the ability to talk to it.


the script:


void main (void)
{
preload_seq(35);
//secuence for closing the fence
preload_seq(36);
//secuence for opening the fence

	int &donk = sp_editor_num(&current_sprite);
	editor_type(&donk, 0);
	int &myflag = editor_seq(&donk, -1);
// I made variable &myflag to track if the fence is open (1) or closed (0)

	int &donk2 = sp_editor_num(&current_sprite);
	editor_type(&donk2, 0);
	int &myflag2 = editor_seq(&donk2, -1);
// I made variable &myflag2 to change &myflag at the end of the script if the fence opens of closes
}

void talk(void)
{ 

freeze(1);
//freeze dink

 if (&myflag == 0)
// look if fence is closed If closed: 
	{
	choice_start()
	"open fence"
	"leave fence"
	choice_end();
	//give the option to open the fence of to just leave it as it is

	if (&result == 1)
	// procedure for opening the fence
       		{
		wait(400);       
		playsound(7, 22050, 0,0,0);

		int &hold = sp_editor_num(&current_sprite);

		editor_type(&hold, 2);
		editor_seq(&hold, 36);
		editor_frame(&hold, 5);

		sp_seq(&current_sprite, 36);
		sp_hard(&current_sprite, 1);
		draw_hard_sprite(&current_sprite);
         
		&myflag2 = 1;
		//adjust &myflag2 to change the value of &myflag at the end of the script
		}
	}

if (&myflag == 1)
// look if fence is closed If open:
//(because &myflag gets edited at the end of the script it doesn't count closed as it is just closed by the above part of the script)
	{ 
	choice_start()
	"close fence"
	"leave fence"
	choice_end();
	//give the option to close the fence of to just leave it as it is

		if (&result == 1)
		// procedure for closing the fence
		{
		move_stop(1, 2, 300,1);
		move_stop(1, 4, 73, 1);
         
		// move dink so he wont get stuck in the harness of the fence when it is reaplied
		wait(200);
		playsound(7, 22050, 0,0,0);
	
		int &hold = sp_editor_num(&current_sprite);
         
		editor_type(&hold, 4);
		editor_seq(&hold, 35);
		editor_frame(&hold, 5);

		sp_seq(&current_sprite, 35);
		sp_hard(&current_sprite, 0);
		draw_hard_sprite(&current_sprite);

		&myflag2 = 0;
		//adjust &myflag2 to change the value of &myflag at the end of the script
		}
	}

&myflag = &myflag2;
//adjust &myflag with &myflag2 so the it corresponds with the status of the fence

unfreeze (1);
// unfreeze dink
}


Edited so code is better readable, thanks MsDink for the tip on how to do that
July 7th 2010, 06:34 AM
custom_msdink.png
MsDink
Peasant She/Her New Zealand
Tag - Umm.. tag, you're it? 
Try ... 'code' inside square brackets... [c***]
then paste your script
'/code' also inside brackets [/c*** ]
(can't do it properly to show you or it puts this inside code lines hehe, most unhelpful)
That makes it easier to see what line things are on without you having to underscore (sorry I am not able to help with your actual script but someone else will

so
square bracket code square bracket
paste your script minus the underscores
blah
blah etc

square bracket /slash code square bracket
and it looks like that ^

Then whoever helps can say you need xxx on line 4 or whatever - easier to help you as its a longish script
July 7th 2010, 08:30 AM
custom_iplaydink.gif
iplaydink
Peasant He/Him Sweden
Hmm.. 
To busy to read right now but I wouldn't put a comment line between the condition of an "if" and the opening {, it could crash things.

Like you've done at many locations.
example:
if(&myflag == 0)
// look if fence is closed If closed:
{
//rest of the code
}

should be
either
// look if fence is closed If closed:
if(&myflag == 0)
{
//rest of the code
}

or
if(&myflag == 0)
{
// look if fence is closed If closed:
//rest of the code
}


July 7th 2010, 08:51 AM
peasantfr.gif
Magicman helped me on IRC, so it finally works now

Feels good to have my first actual script working
now the rest of the DMOD luckily it will get easier as I learn things so I don't have to puzzle 4 hours on a script and still need to ask for helf after that.

Gonna change the commentlines thanks for the tip.
July 7th 2010, 08:52 AM
wizardb.gif
Kyle
Peasant He/Him Belgium
 
You actually change the editor_seq and editor_frame when you open/close the fence. So, next time you enter the screen and its main function is run, it won't return 0 or 1, it will return 35 or 36.

Edit: nvm, 1 minute too late with it Btw, for your first script, that one is an advanced one
July 7th 2010, 09:08 AM
dinkdead.gif
Edit: Ok I was late too, and could well be talking rubbish anyway so go with what you have now

It would probably be easier not to use the editor_stuff for something like this and just set the sequence and frame normally depending on whether the fence should be open or closed. Open/closed could be stored in a global variable, or there is a trick you can use by 'abusing' editor_seq etc....

Here:
void main (void)
{
	//preload_seq not really needed

	int &donk = sp_editor_num(&current_sprite);
	int &open = editor_seq(&donk, -1);
	
	//Not using editor_seq as the real sequence here, but just giving it
	//a value of 0 or 1 to see if the fence is open.
	//See further down for where this is set...

	//Main is run when entering the screen so you need to check here if the fence is open
	if (&open == 1)
	{
		//Fence open
		sp_pseq(&current_sprite, 36);
		//sp_seq is for animations, use sp_pseq for non-moving stuff
		sp_pframe(&current_sprite, 5);
		//same as seq and pseq
		sp_hard(&current_sprite, 0);
		//sp_hard is weird - 0 is hard, 1 is not hard
		draw_hard_sprite(&current_sprite);
	}
	if (&open == 0)
	{
		//Fence closed
		sp_pseq(&current_sprite, 35);
		sp_pframe(&current_sprite, 5);
		sp_hard(&current_sprite, 1);
		draw_hard_sprite(&current_sprite);
	}
}

void talk (void)
{
	freeze(1);

	if (&open == 0)
	{
		//Fence is closed.
		choice_start();
		"Open fence"
		"Leave fence"
		choice_end();

		if (&result == 1)
		{
			//procedure for opening the fence
			wait(400);
			playsound(7, 22050, 0, 0, 0);

			sp_pseq(&current_sprite, 36);
			sp_hard(&current_sprite, 1);
			draw_hard_sprite(&current_sprite);

			//Set editor_seq so it remembers if it's open or closed
			editor_seq(&donk, 1);
			&open = 1;
		}
		unfreeze(1);
		return;
		//return basically means "stop here".
		//So it doesn't matter that &open has just been set to 1
		//because the next part won't run until you talk to the fence again.
	}

	if (&open == 1)
	{
		//Fence is open.
		choice_start();
		"Close fence"
		"Leave fence"
		choice_end();

		if (&result == 1)
		{
			//procedure for closing the fence
			move_stop(1, 2, 300, 1);
			move_stop(1, 4, 73, 1);
			wait(200);
			playsound(7, 22050, 0, 0, 0);

			sp_pseq(&current_sprite, 35);
			sp_hard(&current_sprite, 0);
			draw_hard_sprite(&current_sprite);

			//Set editor_seq so it remembers if it's open or closed
			editor_seq(&donk, 0);
			&open = 0;
		}
	}
	unfreeze(1);
}


You could just make &open into a global variable and leave out all editor stuff if you preferred, but this is a handy trick.

And I didn't test that, so I hope it works
July 7th 2010, 10:40 AM
peasantfr.gif
Although I already had the script working it still had some usefull information for future scrips like the global value option and the return (saw that in some scripts but did not find out yet what it was for exactly).
I used the editor_seq instead of a global script reason is that now I can just copy the fence without having to add a new global variable and edit the script if I want to make more.
July 7th 2010, 02:24 PM
custom_iplaydink.gif
Iplaydink
Peasant He/Him Sweden
Hmm.. 
Congratulations! Quite complecated for a first script too! Looking forward for your dmod.
July 7th 2010, 02:26 PM
custom_skull.gif
Skull
Peasant He/Him Finland bloop
A Disembodied Sod 
Remember not to sink yourself into too complicated scripts in the very beginning.
July 7th 2010, 03:26 PM
wizardb.gif
Kyle
Peasant He/Him Belgium
 
Well I think when you first conceptualize a simple feature like a fence opening and closing you don't expect it to be this complicated But you'll find that some things will just be seriously hard to do, even when it's a stupid little thing On the other hand, I think I've only encountered something that I wanted that wasn't possible once or twice So stick to it, endure, and you'll reap the benefits^^
July 8th 2010, 01:17 AM
peasantfr.gif
Well I knew I was making it hard for myself to start with this script, but that's just what works best for me. Ofourse I started with looking at different tutorials to start understand the basics of scripting. After that I knew that making a conversation and other standard things are not that hard to do. So that wouldn't really be a challenge and therefor just be a bit boring after a few scripts. Nothing wrong with making those scripts, guess I will make a lot of them in the future, but when I start with something I want to have the idea I accomplished something good very early on to keep me motivated and therefor I started with a bit harder script. Basicly I do something hard to motivate myself when it works than do lot of easier things and when I get bored I start doing something hard again and repeat that, so I keep motivated.
Also since I had no good idea for a storyline yet it was no use making these scripst already. So I started with a fence which I know I will use somewhere in the story while thinking out the storyline.

Now I got my storyline complete so gonna make some easier scripts now, but there still are some things I want dink to do in the storyline which require maybe even more complicated scripts than this fence. But by the time I get there I will get that to work aswell, even if I have to work day and night to get it like I want. I am a perfectionist with a lot of patience.
July 8th 2010, 04:37 AM
wizardb.gif
Kyle
Peasant He/Him Belgium
 
That's a wonderful work ethic Really looking forward to the stuff you're going to pull off then^^
July 8th 2010, 06:54 AM
custom_iplaydink.gif
Iplaydink
Peasant He/Him Sweden
Hmm.. 
That's my girl! Now go finish the dmod, and if you encounter any problems we are happy to help.