Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 06-04-2007, 11:03 AM
killerogue killerogue is offline
Registered Omega
killerogue's Avatar
Join Date: Apr 2006
Location: United States
Posts: 1,920
killerogue is on a distinguished road
Send a message via AIM to killerogue Send a message via MSN to killerogue
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:
function onCreated() {
  
core this;
}

function 
setValue(oldValnewVal)
(@ 
oldVal) = (@ newVal); 
NPC 2

PHP Code:
function onCreated() {
  
this.on true;
  
this.on core.setValue(this.on, (this.on = !this.on));
  echo(
this.on);

Echoes nothing. >_>
__________________


REMEMBER, IF YOU REP ME, LEAVE A NAME!

Quote:
Originally Posted by haunter View Post
Graal admins don't die. They go to hell and regroup.
Quote:
Originally Posted by Inverness View Post
Without scripters, your graphics and levels wouldn't do anything but sit there and look pretty.
Reply With Quote
  #2  
Old 06-04-2007, 01:54 PM
Skyld Skyld is offline
Script-fu
Skyld's Avatar
Join Date: Jan 2002
Location: United Kingdom
Posts: 3,914
Skyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud of
Send a message via AIM to Skyld
PHP Code:
this.on core.setValue(this.on, (this.on = !this.on)); 
Firstly, I am not sure that (this.on = !this.on) will work there; it is probably doing comparison instead of assignation.

Secondly, this is what your function is probably actually doing in this context:
PHP Code:
(@ true) = (@ false); 
Finally, you haven't returned anything from setValue() to set this.on to, so it is probably overwriting it with NULL.
__________________
Skyld
Reply With Quote
  #3  
Old 06-04-2007, 02:01 PM
Twinny Twinny is offline
My empire of dirt
Twinny's Avatar
Join Date: Mar 2006
Location: Australia
Posts: 2,422
Twinny is just really niceTwinny is just really nice
Send a message via AIM to Twinny
this.toggle = !this.toggle; will switch between true and false. It's great!
Reply With Quote
  #4  
Old 06-04-2007, 02:39 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
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..
__________________
Reply With Quote
  #5  
Old 06-04-2007, 06:38 PM
zokemon zokemon is offline
That one guy...
zokemon's Avatar
Join Date: Mar 2001
Location: Sonoma County, California
Posts: 2,925
zokemon is a jewel in the roughzokemon is a jewel in the rough
Send a message via ICQ to zokemon Send a message via AIM to zokemon Send a message via MSN to zokemon Send a message via Yahoo to zokemon
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:
function onCreated() {
  
core this;
}

public function 
setValue(oldValnewVal)
(@ 
oldVal) = newVal
NPC 2

PHP Code:
function onCreated() {
  
this.on true;
  
core.setValue("this.on", (this.on = !this.on));
  echo(
this.on);

I know I changed it quiet a bit but it is sort of hard to see exactly what you want, sorry.

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));")
__________________
Do it with a DON!
Reply With Quote
  #6  
Old 06-04-2007, 06:47 PM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
HTML Code:
public function setValue(oldVal, newVal)
(@ oldVal) = newVal;  
Bad names, here try this

HTML Code:
public function setValue(stringName, newValue)
{
  (@ temp.stringName) = temp.newValue; 
} 
Also, all you're doing with 'this.on' is re-placing it into your core NPC...
You'd use a function like this on an item database, changing local item flags. [updating etc]
__________________
Reply With Quote
  #7  
Old 06-04-2007, 06:49 PM
zokemon zokemon is offline
That one guy...
zokemon's Avatar
Join Date: Mar 2001
Location: Sonoma County, California
Posts: 2,925
zokemon is a jewel in the roughzokemon is a jewel in the rough
Send a message via ICQ to zokemon Send a message via AIM to zokemon Send a message via MSN to zokemon Send a message via Yahoo to zokemon
Quote:
Originally Posted by xAndrewx View Post
HTML Code:
public function setValue(oldVal, newVal)
(@ oldVal) = newVal;  
Bad names, here try this

HTML Code:
public function setValue(stringName, newValue)
{
  (@ temp.stringName) = temp.newValue; 
} 
Also, all you're doing with 'this.on' is re-placing it into your core NPC...
You'd use a function like this on an item database, changing local item flags. [updating etc]
Quote:
Originally Posted by zokemon View Post
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));")
Didn't realize someone would reply so fast!
__________________
Do it with a DON!
Reply With Quote
  #8  
Old 06-04-2007, 06:51 PM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
your second edit makes no sense...
__________________
Reply With Quote
  #9  
Old 06-04-2007, 07:35 PM
killerogue killerogue is offline
Registered Omega
killerogue's Avatar
Join Date: Apr 2006
Location: United States
Posts: 1,920
killerogue is on a distinguished road
Send a message via AIM to killerogue Send a message via MSN to killerogue
Quote:
Originally Posted by Chompy View Post
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..
Chompy in this case, I believe you are ABSOLUTELY wrong as Chandler made something of this nature before. I just can't remember how it went.

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
__________________


REMEMBER, IF YOU REP ME, LEAVE A NAME!

Quote:
Originally Posted by haunter View Post
Graal admins don't die. They go to hell and regroup.
Quote:
Originally Posted by Inverness View Post
Without scripters, your graphics and levels wouldn't do anything but sit there and look pretty.
Reply With Quote
  #10  
Old 06-04-2007, 08:56 PM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
You don't have to reference temp variables with temp. just leave that out, it looks better.
PHP Code:
public function saveItems() {
  
temp.file =
  
temp.=
  
temp.path =
  
temp.data 0;
  
  for (
this.items.size() - 1> -1--) {
    if (
this.items[i].archname != null) {
      
data this.items[i].getSaveData();
      
file.(@ "item" data[0]) = {data[1], data[2], data[3], data[4]};
    }
  }
  
path MudControl.containerpath this.conttype "/cont" this.contid ".txt";
  
file.saveVars(path0);

Versus
PHP Code:
public function saveItems() {
  for (
temp.this.items.size() - 1temp.> -1temp.--) {
    if (
this.items[temp.i].archname != null) {
      
temp.data this.items[temp.i].getSaveData();
      
temp.file.(@ "item" temp.data[0]) = {temp.data[1], temp.data[2], temp.data[3], temp.data[4]};
    }
  }
  
temp.path MudControl.containerpath this.conttype "/cont" this.contid ".txt";
  
temp.file.saveVars(temp.path0);

__________________
Reply With Quote
  #11  
Old 06-04-2007, 09:37 PM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
Yes you do, else it's stored.
__________________
Reply With Quote
  #12  
Old 06-04-2007, 09:48 PM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
Quote:
Originally Posted by xAndrewx View Post
Yes you do, else it's stored.
Wrong, if you'd notice in the first set of code I declare the temp variables before the actual script, this means that those variables are now temp and can be referenced without temp. and they will still be cleared after the function has ended.

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.
__________________

Last edited by Inverness; 06-04-2007 at 10:01 PM..
Reply With Quote
  #13  
Old 06-04-2007, 10:02 PM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
Do you test anything you say?

HTML Code:
function onCreated()
{
  temp.testA = 0;
  temp.myTest = "|hia";
  testA = "lol";
  
  this.onTest();
  scheduleevent(3, "Test", "");
}
function onTest()
{
  echo(temp.myTest);
  echo(testA);
}
Constantly returns "lol".
__________________
Reply With Quote
  #14  
Old 06-04-2007, 10:06 PM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
Quote:
Originally Posted by xAndrewx View Post
Do you test anything you say?

PHP Code:
function onCreated()
{
  
temp.testA 0;
  
temp.myTest "|hia";
  
testA "lol";
  
  
this.onTest();
  
scheduleevent(3"Test""");
}
function 
onTest()
{
  echo(
temp.myTest);
  echo(
testA);

Constantly returns "lol".
I just tried that, I don't get anything echoed. You've obviously made a mistake before that current compilation.
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:
function onCreated() {
  
temp.0;
  
"HELLO!";
  echo(
temp.r);

This script echos "HELLO!";

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.

Btw, I recommend the avoidance of any uppercase letters in variable names, object names not included of course.
__________________

Last edited by Inverness; 06-04-2007 at 10:22 PM..
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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.