Quote:
|
Originally Posted by Draenin
Because that format is mainly used for arrays, which are a little different than a plain variable.
This is a lot more efficient, though: (Not to mention, it should work.)
PHP Code:
function onCreated()
{
this.value = 0;
}
function onPlayerTouchsMe()
{
if (this.value = 0);
this.value = 1;
player.chat = "On!";
}
else
{
this.value = 0;
player.chat = "Off!";
}
The else case is a bit unnecessary, though, as the variable this.value will stay at 0 unless you change it, which you have done in your if case.
|
If you're going to use PHP tags, please format your code so it's readable.
Also, there are a few errors, such as the semi-colon after the if statement, and the fact that you are missing a curly-brace at the end (which would have been easily distinguishable if you had formatted your code

)
Fixed (Differentish) version:
PHP Code:
function onCreated() {
this.value = false; // Kind of redundant, values get reset when the NPC is created serverside anyway.
}
function onPlayerTouchsMe() {
this.value = !this.value;
if(this.value) {
player.chat = "On";
} else {
player.chat = "Off";
}
}