quick question

Moderator: Event DM

Post Reply
User avatar
Crimzonfist
Prince of Bloated Discourse
Posts: 199
Joined: Thu Aug 25, 2005 7:44 am
Location: Michigan

quick question

Post by Crimzonfist » Wed Jul 26, 2006 6:01 am

the wording for the return() function in the lexicon is a bit confusing to me. I assume when its run in a script it stops said script. X:| but im realy not sure
Member - Ivory Order of the Sun
Journeyman of the AKN

"True integrity is doing the right thing, even when no ones watching."
User avatar
Heed
Scholar of Fools
Posts: 377
Joined: Sat Jul 17, 2004 11:13 am
Location: Dasein
Contact:

Post by Heed » Wed Jul 26, 2006 7:20 am

Yeah, a return will stop any code following it from executing.
Thought thinks itself.
_________________
A Game is a machine that can get into action only if the players consent to become puppets for a time.
--Marshall McLuhan,
Understanding Media
User avatar
Crimzonfist
Prince of Bloated Discourse
Posts: 199
Joined: Thu Aug 25, 2005 7:44 am
Location: Michigan

Post by Crimzonfist » Wed Jul 26, 2006 4:59 pm

thanx Heed
Member - Ivory Order of the Sun
Journeyman of the AKN

"True integrity is doing the right thing, even when no ones watching."
User avatar
jaythespacehound
Apprentice Scholar
Posts: 940
Joined: Wed Sep 22, 2004 6:52 am
Location: Hobart Australia (feels like a small island sometimes...hang on it is) GMT+10

Post by jaythespacehound » Fri Aug 18, 2006 12:15 pm

If you use it in a function, it will also return the value given in Return something;

ie:

Code: Select all

// This function gets the gold of a player and calculates the new gold value to set.

int GetNewGold(object oPlayer, int iGoldMult)
{
// Get how much gold the player has
int iGold = GetGold(oPlayer);

// Get how much he should end up with
int iGoldFinal = (iGold * iGoldMult);

// Get how much gold to add
int iGoldToAdd = (iGoldFinal - iGold);

return iGoldToAdd;
}

void main()
{
// Get the PC in the conversation
object oPC = GetPCSpeaker();

// create a random reward from 1 - 3 times the current gold value
int iReward = (Random(2) + 1);

//Use the above function to find how much gold the player should be given
int iAddGold = GetNewGold(oPC, iReward);

//adds the reward
GiveGoldToCreature(oPC, iAddGold);
}
Er... that ended up being a rather long example...
Anyway here's what it does:

Like all scripts, it starts at void main()

It then gets the PC to be rewarded, namely the PC currently talking to the npc this script is on.

Then it creates a random number from 1 to 3 (Random(n) generates a random number from 0 to n hence the + 1)

Then it gets how much gold needs to be added using the function GetNewGold, which was created above the void main statement by:

Getting how much gold the player has,
Multiplying that by the random number.
Working out the difference between the gold the player has and how much he should have,
returning that difference to the void main script,

The void main then uses that to add that amount of gold to the player's pile. :)


See the bit before each function sets what kind of information it returns.

void main() for example

the prefix is void, which means it returns nothing.

For GetNewGold, the prefix is int. Which means it returns an integer value.

Hope that made sense and helped someone . :)
It certainly gave me something to do heh.
Jay
Post Reply