Server Totals
Ferrell - (1)
M'Chek - (1)
Visimontium - (0)
Wilderness - (0)
Elysia - (0)
Le'Or - (0)
Deglos - (0)
Underdark - (0)
Mikona - (0)
Total players: 2
Gallery

Links Menu

quick question

Moderators: Nighthawk4, Dungeon Masters

quick question

PostAuthor: 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
Crimzonfist
Prince of Bloated Discourse
 
Posts: 199
Joined: Thu Aug 25, 2005 7:44 am
Location: Michigan

PostAuthor: 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
Heed
Scholar of Fools
 
Posts: 378
Joined: Sat Jul 17, 2004 11:13 am
Location: Dasein

PostAuthor: 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
Crimzonfist
Prince of Bloated Discourse
 
Posts: 199
Joined: Thu Aug 25, 2005 7:44 am
Location: Michigan

PostAuthor: 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
User avatar
jaythespacehound
Apprentice Scholar
 
Posts: 941
Joined: Wed Sep 22, 2004 6:52 am
Location: Hobart Australia (feels like a small island sometimes...hang on it is) GMT+10


Return to NWN Scripting

Who is online

Registered users: Bing [Bot], Google [Bot]