Page 1 of 1

quick question

PostPosted: Wed Jul 26, 2006 6:01 am
Author: Crimzonfist
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

PostPosted: Wed Jul 26, 2006 7:20 am
Author: Heed
Yeah, a return will stop any code following it from executing.

PostPosted: Wed Jul 26, 2006 4:59 pm
Author: Crimzonfist
thanx Heed

PostPosted: Fri Aug 18, 2006 12:15 pm
Author: jaythespacehound
If you use it in a function, it will also return the value given in Return something;


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.