Massassi Forums Logo

This is the static archive of the Massassi Forums. The forums are closed indefinitely. Thanks for all the memories!

You can also download Super Old Archived Message Boards from when Massassi first started.

"View" counts are as of the day the forums were archived, and will no longer increase.

ForumsCog Forum → master cog with difficulty settings
master cog with difficulty settings
2004-09-28, 8:01 AM #1
This master cog crashes the game now I've changed it to check for the difficulty level. I guess I have not put the jkSyncForcePowers() or the timer in the right place, with all the brackets I've used. Any ideas?

Code:
#Level master COG
#Generated by JED 0.95 beta

symbols
message   startup
message timer
int       player    local
end

code

startup:
  // Register COG as master COG
  SetMasterCOG(GetSelfCOG());
  player = GetLocalPlayerThing();
  // Initialise Goals
  SetInv(player, 99, 1000);

difficulty = GetDifficulty();

if (difficulty == 0)
	{
  	SetGoalFlags(player,3,1);
  	// Give player weapons and ammo
  	SetInv(player, 1, 1);   // fists
  	SetInv(player, 2, 1);   // briar
  	SetInv(player, 3, 1);   // ST Rifle
  	SetInv(player, 4, 10); // Thermal Detonators
  	SetInv(player, 11, 400);   // Energy
  	// Initialize weapon.
  	SetFireWait(player, -1);
  	SetMountWait(player, 0);
  	SetCurInvWeapon(player, 1);
  	SelectWeapon(player, AutoSelectWeapon(player, 1));
	}

if (difficulty == 1)
	{
	SetGoalFlags(player,3,1);
  	// Give player weapons and ammo
  	SetInv(player, 1, 1);   // fists
  	SetInv(player, 2, 1);   // briar
  	SetInv(player, 4, 6); // Thermal Detonators
  	SetInv(player, 11, 200);   // Energy
  	// Initialize weapon.
  	SetFireWait(player, -1);
  	SetMountWait(player, 0);
  	SetCurInvWeapon(player, 1);
  	SelectWeapon(player, AutoSelectWeapon(player, 1));
	}

if (difficulty == 2)
	{
  	SetGoalFlags(player,3,1);
  	// Give player weapons and ammo
  	SetInv(player, 1, 1);   // fists
  	SetInv(player, 2, 1);   // briar
  	SetInv(player, 10, 1);   // Lightsaber
  	SetInv(player, 11, 100);   // Energy
  	// Initialize weapon.
  	SetFireWait(player, -1);
  	SetMountWait(player, 0);
  	SetCurInvWeapon(player, 1);
  	SelectWeapon(player, AutoSelectWeapon(player, 1));
	}

	SetTimer(15);

timer:

difficulty = GetDifficulty();

if (difficulty == 2)
	{
  	SetInv(player, 20, 6);
  	SetInv(player, 14, 6*50);

	SetInv(player, 21, 3.0);
	SetInvAvailable(player, 21, 1); 

	SetInv(player, 22, 1.0);
	SetInvAvailable(player, 22, 1); 

	SetInv(player, 23, 1.0);
	SetInvAvailable(player, 23, 1); 

	SetInv(player, 24, 2.0);
	SetInvAvailable(player, 24, 1); 

	SetInv(player, 25, 2.0);
	SetInvAvailable(player, 25, 2); 

	SetInv(player, 26, 2.0);
	SetInvAvailable(player, 26, 2);

	jkSyncForcePowers();
	return;
	}

	else
	return;

end
2004-09-28, 8:18 AM #2
There is no return; statement at the end of the startup handler (right before timer: statement). This means the timer handler will always run immediately after the startup handler is finished (as well as 15 seconds later due to the SetTimer(15); statement). The lack of the return; statement is likely not what is wanted, and could be the cause of the problem.
2004-09-28, 2:05 PM #3
There's also no return; at the end of the timer message.

Yes, there is one in the "else" block, but if the difficulty == 2 then it won't be executed.
As a matter of fact, you don't even need that "else", because if the difficulty isn't equal to 2, it's going to "return;" anyway.
May the mass times acceleration be with you.
2004-09-30, 12:55 AM #4
I added in the return; commands (i'm not sure I put the timer return; in the correct place - will it work now if difficulty is 2?). So far, no change.

Then I thought: maybe you have to set the forcemana and forcerank bins 14 and 20 to 0 for characters who have no powers, just to give the jkSyncForcePowers command something to do.

There was a definite change: my computer didn't crash after having the loadscreen go funny shades of green and yellow straight to Windows - it crashed just after the loadscreen, and the screen went black as if it was thinking about almost starting the level. Am I closer to success? :)

Cog so far:

symbols
message startup
message timer
int player local
end

code

startup:
// Register COG as master COG
SetMasterCOG(GetSelfCOG());
player = GetLocalPlayerThing();
// Initialise Goals
SetInv(player, 99, 1000);

difficulty = GetDifficulty();

if (difficulty == 0)
{
SetGoalFlags(player,3,1);
// Give player weapons and ammo
SetInv(player, 1, 1); // fists
SetInv(player, 2, 1); // briar
SetInv(player, 3, 1); // ST Rifle
SetInv(player, 4, 10); // Thermal Detonators
SetInv(player, 11, 400); // Energy
// Initialize weapon.
SetFireWait(player, -1);
SetMountWait(player, 0);
SetCurInvWeapon(player, 1);
SelectWeapon(player, AutoSelectWeapon(player, 1));
}

if (difficulty == 1)
{
SetGoalFlags(player,3,1);
// Give player weapons and ammo
SetInv(player, 1, 1); // fists
SetInv(player, 2, 1); // briar
SetInv(player, 4, 6); // Thermal Detonators
SetInv(player, 11, 200); // Energy
// Initialize weapon.
SetFireWait(player, -1);
SetMountWait(player, 0);
SetCurInvWeapon(player, 1);
SelectWeapon(player, AutoSelectWeapon(player, 1));
}

if (difficulty == 2)
{
SetGoalFlags(player,3,1);
// Give player weapons and ammo
SetInv(player, 1, 1); // fists
SetInv(player, 2, 1); // briar
SetInv(player, 10, 1); // Lightsaber
SetInv(player, 11, 100); // Energy
// Initialize weapon.
SetFireWait(player, -1);
SetMountWait(player, 0);
SetCurInvWeapon(player, 1);
SelectWeapon(player, AutoSelectWeapon(player, 1));
}

SetTimer(15);
return;

timer:

if (difficulty == 0)
{
// Force ranking
SetInv(player, 20, 0);
SetInv(player, 14, 0);
}

if (difficulty == 1)
{
// Force ranking
SetInv(player, 20, 0);
SetInv(player, 14, 0);
}

if (difficulty == 2)
{
// Force ranking
SetInv(player, 20, 6);
SetInv(player, 14, 6*50);

// FORCE POWERS

// Jump
SetInv(player, 21, 3.0);
SetInvAvailable(player, 21, 1);

// Speed
SetInv(player, 22, 1.0);
SetInvAvailable(player, 22, 1);

// SEEING
SetInv(player, 23, 1.0);
SetInvAvailable(player, 23, 1);

// PULL
SetInv(player, 24, 2.0);
SetInvAvailable(player, 24, 1);

// HEALING
SetInv(player, 25, 2.0);
SetInvAvailable(player, 25, 2);

// PERSUASION
SetInv(player, 26, 2.0);
SetInvAvailable(player, 26, 2);
}

jkSyncForcePowers();

return;

end
2004-09-30, 1:33 AM #5
Well the first thing that springs to calls out to me (and I wasn't totally sure about how much you knew about statement structure from the "kill bugs" thread) is the use of "if-else" statements. Many of the comparative statments you make would benefit hugely from this test, as it reduces the overhead of having to process "if something - if something - if something" to simply "if something then do it and return to game - else if choose the next appropriate comparison"; basically only perform the comparative tests that you need to for a cog. If an "if" statement fails, it will then logically follow to its accompanying "else if" or "else" statement (if you supply these branching alternatives in your cog, otherwise the cog just "return"s). Hope this info helps :)

For a "politically correct" cog, you'd ideally have "difficulty" set up as a local int in the cog's symbols section. Other than the branching structure as I've mentioned above, nothing immediately leaps out and grabs me (although it is early for me now and I haven't gathered all my marbles yet ;)). With regard to your timer and return messages, they seem OK :). I wouldn't have thought that "getDifficulty()" would throw a tantrum when used as part of a level startup cog but then it might be that the level loads before the game registers what difficulty setting it is. However, I severely doubt this possibility, which leaves me wondering - where does the problem lie :confused:. I'll have to have a re-think (and some breakfast) first ;). If nothing else, there's a few ideas for you to start on :D

Hope this helps :D

-Jackpot
"lucky_jackpot is the smily god..." -gothicX
"Life is mostly froth and bubble, but two things stand in stone,
Kindness in another's trouble, courage in your own"
- "Ye Wearie Wayfarer"
|| AI Builder: compatible with both JK & MotS || My website ||
2004-09-30, 9:29 AM #6
(sobs quietly) ... why can't my computer be less logical!

I lessened the number of ifs a bit (I want the ones in the startup message because I want each difficulty setting to give the player different abilities.) But, no luck so far!:

Code:
symbols
message   startup
message timer
int       player    local
int	difficulty	local
end

code

startup:
  	// Register COG as master COG
  	SetMasterCOG(GetSelfCOG());
  	player = GetLocalPlayerThing();
  	// Initialise Goals
  	SetInv(player, 99, 1000);
   	SetGoalFlags(player,3,1);

 	// Set player basic weapons
	SetInv(player, 1, 1);   // fists
  	SetInv(player, 2, 1);   // briar
  	// Initialize weapon.
  	SetFireWait(player, -1);
  	SetMountWait(player, 0);
  	SetCurInvWeapon(player, 1);
  	SelectWeapon(player, 121);

difficulty = GetDifficulty();

if (difficulty == 0)
	{
  	// Give player character-specific weapons and ammo
  	SetInv(player, 3, 1);   // ST Rifle
  	SetInv(player, 4, 10); // Thermal Detonators
  	SetInv(player, 11, 400);   // Energy
	}

if (difficulty == 1)
	{
  	// Give player character-specific weapons and ammo
  	SetInv(player, 4, 6); // Thermal Detonators
  	SetInv(player, 11, 200);   // Energy
	}

else
	{
  	// Give player character-specific weapons and ammo
  	SetInv(player, 10, 1);   // Lightsaber
  	SetInv(player, 11, 100);   // Energy
	}

	SetTimer(15);
return;

timer:

if (difficulty == 2)
	{
  	// Force ranking
  	SetInv(player, 20, 6);
  	SetInv(player, 14, 6*50);

	// Jump
	SetInv(player, 21, 3.0);
	SetInvAvailable(player, 21, 1); 

	// Speed
	SetInv(player, 22, 1.0);
	SetInvAvailable(player, 22, 1); 

	// SEEING
	SetInv(player, 23, 1.0);
	SetInvAvailable(player, 23, 1); 

	// PULL
	SetInv(player, 24, 2.0);
	SetInvAvailable(player, 24, 1); 

	// HEALING
	SetInv(player, 25, 2.0);
	SetInvAvailable(player, 25, 2); 

	// PERSUASION
	SetInv(player, 26, 2.0);
	SetInvAvailable(player, 26, 2);
	jkSyncForcePowers();
	}

else

	{
	// Force ranking
	SetInv(player, 20, 0);
	SetInv(player, 14, 0);
	jkSyncForcePowers();
	}
	return;

end
2004-09-30, 3:01 PM #7
In startup, add an else where you see it bolded below. Otherwise the last else block will execute if difficulty == 0.
Code:
if (difficulty == 0)
	{
  	// Give player character-specific weapons and ammo
  	SetInv(player, 3, 1);   // ST Rifle
  	SetInv(player, 4, 10); // Thermal Detonators
  	SetInv(player, 11, 400);   // Energy
	}

else if (difficulty == 1)
	{
  	// Give player character-specific weapons and ammo
  	SetInv(player, 4, 6); // Thermal Detonators
  	SetInv(player, 11, 200);   // Energy
	}

else
	{
  	// Give player character-specific weapons and ammo
  	SetInv(player, 10, 1);   // Lightsaber
  	SetInv(player, 11, 100);   // Energy
	}

btw, here's a (slightly confusing) layout of how the if-else statements work. This next code section is a conventional selection of code.
Code:
if(this)
{
	do this;
}
else if(that)
{
	do that;
}
else if(something else)
{
	do something here;
}
else
{
	error;
}

The above is the equivalent to the code below (due to the imaginary braces around the next command).
Code:
if(this)
{
	do this;
}
else
{
	if(that)
	{
		do that;
	}
	else
	{
		if(something else)
		{
			do something here;
		}
		else
		{
			error;
		}
	}
}

Thisis how JK and programming languages like C and Java process if-else statements.

My C++ text showed me this, and I always thought this was really cool; hopefully it helps your understanding of the if-else stuff (as it did mine). :)
May the mass times acceleration be with you.
2004-09-30, 3:32 PM #8
A well laid-out example Slaw - that was basically what I was trying to get across, structure wise :)

That and you know that I prefer the opening brace on the same line as the test condition, but it's entirely a matter of preference ;) :D

-Jackpot
"lucky_jackpot is the smily god..." -gothicX
"Life is mostly froth and bubble, but two things stand in stone,
Kindness in another's trouble, courage in your own"
- "Ye Wearie Wayfarer"
|| AI Builder: compatible with both JK & MotS || My website ||
2004-10-01, 4:07 PM #9
Something wierd is happening ...

I decided to remove my cog and replace it with a standard master cog, generated by jed, just to use my level again. This is what happened: the level loads fine for any player on Hard difficulty, but crashes instantly for players on Easy and Medium difficulty. So it may not have been the cog at all that was the problem.

I just don't understand it ... the walkplayer thingflags aren't set for Hard setting only ...:confused:

↑ Up to the top!