The Dink Network

Scripting help

December 23rd 2014, 06:41 PM
maiden.gif
So, I'm making my first D-Mod for the Silent Protagonist contest, and a couple of my scripts are not acting as I think they should. I was wondering if people could help with why they might not be working.

My first script contains the following (doctored for after story hits 10)
void main( void )
{
	if (&story < 10)
	{
		&wid = create_sprite(364, 218, 16, 411, 1);
    		sp_speed(&wid, 1);
		sp_base_walk(&wid, 410);
    		sp_script(&wid, "T1-B2.c");
	}
}

However, during my play-throughs, &wid never appears. The script "T1-B2.c" worked fine when he was just placed on the map, so I know the problem is somewhere here.

My other major problem involves a trader. Part of the script is supposed to checks if you don't have a particular item, that you have enough gold for it, and that your inventory is not full. While the third one is impossible without cheating, I've still built in for it for use in future D-Mods. However, when trying to buy an item, it triggers on this even with an empty inventory. Here's the code for an edited throwing axe item (I set the cost to one for testing purposes.)
		&invitem = count_item("item-AXE");
		if (&invitem > 0)
		{
			say_stop("`2You already have one of those.", &trader);
			unfreeze(1);
			return;
		}
		if (&gold < 1)
		{
			say_stop("`2You don't have enough gold for that.", &trader);
			wait(200);
			say_stop("`2Come back when you have!", &trader);
			unfreeze(1);
			return;
		}
		&invplace = free_items();
		if (&invplace < 1)
		{
			say_stop("`2You don't appear to be able to carry any more.",&trader);
			wait(200);
			say_stop("`2I guess you won't need this anyway.",&trader);
			unfreeze(1);
			return;
		}

If anyone can see any errors in these, the help would be most appreciated. There are other errors in my code, but they are minor ones, with only aesthetic consequences, so these are the ones I need to fix before release.
December 23rd 2014, 08:14 PM
custom_king.png
redink1
King He/Him United States bloop
A mother ducking wizard 
Are &wid and &invplace defined as global variables in main.c? If not, you need to make sure you declare them as local variables, like this for your first script:

void main( void )
{
	if (&story < 10)
	{
		int &wid = create_sprite(364, 218, 16, 411, 1);
    		sp_speed(&wid, 1);
		sp_base_walk(&wid, 410);
    		sp_script(&wid, "T1-B2.c");
	}
}


'int &wid' makes this a local variable that can only be accessed from this script.
December 23rd 2014, 10:26 PM
maiden.gif
Wow, I think that fixes every error I've made...

Hopefully, that means I should be done very soon.
December 24th 2014, 04:18 AM
dinkdead.gif
Also, you don't need the ".c" in the script name.

sp_script(&wid, "T1-B2");