Blockland Forums > Modification Help

Points Value [Solved by Port]

Pages: << < (3/3)

jes00:


--- Quote from: Port on January 30, 2012, 10:19:03 AM ---They return the value found..?

--- End quote ---
): I still don't understand returns.

Port:

They end the function (stops any code below the statement from running) and give back a value.
For example, if you did echo( getPlayerScore( "some name" ) ); - the value that would be echoed is the value that was specified in the return statement.

Slicksilver:

I'll elaborate with an example.

--- Code: ---$GrannyWasRaped=1;
function wasGrannyRaped()
{
      if($GrannyWasRaped == 1)
      {
            return "Yes!";
      }
      else
      {
            return "Nope!";
      }
}
function tellMeIfGrannyWasRaped()
{
      echo(wasGrannyRaped());
}

--- End code ---
Here you can see that it will echo "Yes!" if $GrannyWasRaped is set to 1, or "Nope!" if it is set to 0.

EDIT: I should also mention the function stops running when it sees a return. This is useful for escaping from bigger functions or loops when you've gotten all the data you need, rather than waiting it out (as in Port's code)

Pages: << < (3/3)

Go to full version