![]() |
Function To Change Value
I feel as if I'm probably missing something asking this, but as anyone here ever made a function to set a new value to an old one?
I was trying to do something like: NPC 1 PHP Code:
PHP Code:
|
PHP Code:
Secondly, this is what your function is probably actually doing in this context: PHP Code:
|
this.toggle = !this.toggle; will switch between true and false. It's great! ^^
|
You can't access this.on from npc1 to npc2.
You give this.on to npc1 and it changes, but npc2 can't get the changed this.on from npc1.. Correct me if I'm wrong.. |
You also should make the setValue() function public in order for other npcs to be able to call it.
EDIT: Here is probably what you are looking for: NPC 1 PHP Code:
PHP Code:
SECOND EDIT: On second thought, that won't work either as "this.on" will be using the first NPC as "this" (in essence it would be the same as doing "core.setValue("core.on", (this.on = !this.on));") |
HTML Code:
public function setValue(oldVal, newVal)HTML Code:
public function setValue(stringName, newValue)You'd use a function like this on an item database, changing local item flags. [updating etc] |
Quote:
Quote:
|
your second edit makes no sense...
|
Quote:
Thanks Chandler, at least I've gotten somewhere now. It's getting the changed value back. But it just continuoulsy echos 0 or 1 depending on how the func is scripted. >_< EDIT: WOW, I really am stupid. I had "this.on = true;" at the beginning of onCreated function. xD Thanks guys :P |
You don't have to reference temp variables with temp. just leave that out, it looks better.
PHP Code:
PHP Code:
|
Yes you do, else it's stored.
|
Quote:
If referencing a variable without the prefix meant its global than why can you reference static variables, most notably in GUI Controls, without the prefix and have them not be global variables? When you reference a variable without the prefix, the engine first looks for a temp variable with the variable name, if it can't find that it will then look for a static (built-in) variable of the current object (this.), and if it can't find that either it defaults to global. Function parameters are automatically declared temp so you don't need to bother with that, any other temp variables you can declare them to 0 at the beginning of the function for readability. Declaring a temp variable to zero initializes it for the duration of the function so the engine will find it before going global. |
Do you test anything you say?
HTML Code:
function onCreated() |
Quote:
Variable names are case sensitive so you probably messed up the name of temp.testA and the name didn't match the name of testA = "lol"; Static variables appear to be an exception to this case-sensitive thing though. PHP Code:
I've already extensively tested this and the only mistake I made was when I thought temp.variable; automatically initialized it to zero. Your input is not going to change anything. Also another reason I want the custom object types, so I can have my own static and read-only variables. :frown: Btw, I recommend the avoidance of any uppercase letters in variable names, object names not included of course. |
| All times are GMT +2. The time now is 08:35 AM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.