Author Topic: Variable & Value Help [Answered]  (Read 1286 times)

Unless I read the OP wrong, you want to know how to figure this out yourself?

You can call .dump(); on any object. It'll tell you every single function and variable for that object, and it'll briefly describe a lot of the built in engine functions and how to use them. Since those things are all client variables, you can call findClientByName("Yola").dump(); to see every variable and method for your client.

there is a way to get your own score client sidedly.

Code: [Select]
function getMyScore()
{
%Count = NPL_List.rowCount();

for(%a = 0; %a < %Count; %a++)
{
%Row = NPL_List.getRowText(%a);
if(getField(%Row, 1) $= $pref::Player::NetName)
return getField(%Row, 2);
}
}

Okay, I'm trying to understand the code itself.
Your using the F2 GUI?  And picking the player you are using the players netname pref, then changing rows to where the score number is displayed.
If that is correct then my only non-understanding is what is the variable name for the score now, I don't see what actually returns the score number

Unless I read the OP wrong, you want to know how to figure this out yourself?

You can call .dump(); on any object. It'll tell you ever single function and variable for that object, and it'll briefly describe a lot of the built in engine functions and how to use them. Since those things are all client variables, you can call findClientByName("Yola").dump(); to see every variable and method for your client.
I might be in love with you now.


Line 9.
Okay, let me rephrase the question, thank you though, how would I apply the score number now?
And besides that, what exactly is the purpose and/or use of return

Return does one thing, it passes on whatever results from the expression right next to it (in this case, getField(%Row, 2)) and uses that as the result of the function when used as an expression.

Example:

if you used
echo(getMyScore());

when your score was 17, then that would echo 17 into the console. That's because getMyScore() returned 17, and it was passed on as the argument for the function echo.

As for your first question, what do you mean 'apply'?

Return does one thing, it passes on whatever results from the expression right next to it (in this case, getField(%Row, 2)) and uses that as the result of the function when used as an expression.

Example:

if you used
echo(getMyScore());

when your score was 17, then that would echo 17 into the console. That's because getMyScore() returned 17, and it was passed on as the argument for the function echo.

As for your first question, what do you mean 'apply'?
You answered both my questions with that answer, thank you very much

Okay, let me rephrase the question, thank you though, how would I apply the score number now?
And besides that, what exactly is the purpose and/or use of return
What do you mean by apply? That'll set that variable to your score and you can use it however you like.

Also, return is probably the most useful thing built into programming languages. I literally remember the day I figured it out and was so excited.

It's hard to explain because we get in the habit of saying "It'll return blah", but essentially it makes it so your function translates to a value. For example, findClientByName("name") returns the ID of the client who's name you put in.

Code: [Select]
function hello()
{
      return "hi";
}
echo(hello());
That will echo "hi". You can do stuff like if(clientHasScoreHigherThan(12)) and other cool stuff that is really helpful.

You answered both my questions with that answer, thank you very much
oh okay, lol. yw.

Thank you all a lot for helping me out, I know I'm a noob, one last question is referring back to the post about health.

So if I want to take away 1 health from every single player on the server every 10 seconds, what would be an efficient way of doing this, with a server sided mod obviously.

Thank you all a lot for helping me out, I know I'm a noob, one last question is referring back to the post about health.

So if I want to take away 1 health from every single player on the server every 10 seconds, what would be an efficient way of doing this, with a server sided mod obviously.
Code: [Select]
function healthDegenLoop()
{
for(%i=0;%i<clientGroup.getCount();%i++)
{
if(isObject(clientGroup.getObject(%i).player))
clientGroup.getObject(%i).player.addHealth(-10);
}
$DeGen::Tick = schedule(10000,0,healthDegenLoop);
}

function healthDegenLoop()
{
   for(%i=0;%i<clientGroup.getCount();%i++)
   {
      if(isObject(clientGroup.getObject(%i).player))
         clientGroup.getObject(%i).player.addHealth(-10);
   }
   $DeGen::Tick = schedule(10000,0,healthDegenLoop);
}

Bolded part: I have no idea what you are doing there
Underlined part: Again, no idea
Italicized part: Truthfully, I would be lying if I said I understood this part as well

Bolded part: I have no idea what you are doing there
Underlined part: Again, no idea
Italicized part: Truthfully, I would be lying if I said I understood this part as well
Okay well, do you know how a for loop works?

for(%variable = initial; %variable < condition; %variable += modify)

The first part is what you start the variable at, in this case it starts at 0. It checks to make sure it meets the condition, it's like an if statement that says go ahead if it's true. In this case, it's checking if it's less than the amount of clients in your server. If there is no one on your server, it wont run any of the code inside the loop because 0 is not less than 0. Then, it runs through all the code inside it. At the end, it comes back up to the top, changes the variable by the third part (in this case, it increases it by one) and runs it again until the middle part is false at which point it stops.

clientGroup is a group that holds all of the client objects. If you get the 0 (first) object from the group, it will be the first person on the f2 list when not sorted. This is also the first (oldest) person that connected. So, getObject() gets the client, %i tells it which client. From the for loop I explained earlier, you should know that %i increases by one until it's greater or equal to the amount of clients in the server. This means it will, one by one, get every client in the server. Your italicized part is the same thing, so yeah.

for(%variable = initial; %variable < condition; %variable += modify)
Programming is more dynamic than that you sillypants!

For example, you can use the for loop structure to create a loop that will go through all the files in any directory that have a specific extension:
for(%File = FindFirstFile(%Path @ "*." @ %Ext); %File !$= ""; %File = FindNextFile(%Path @ "*." @ %Ext))

That's on the more complicated side, but like I said. Very dynamic.

Programming is more dynamic than that you sillypants!

For example, you can use the for loop structure to create a loop that will go through all the files in any directory that have a specific extension:
for(%File = FindFirstFile(%Path @ "*." @ %Ext); %File !$= ""; %File = FindNextFile(%Path @ "*." @ %Ext))

That's on the more complicated side, but like I said. Very dynamic.
Yeah, it's dynamic, but it follows the same exact setup.

for(%file = initialValue; %file !$= condition; %file = modifiedValue)