Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 05-25-2010, 06:00 AM
Jiroxys7 Jiroxys7 is offline
Hazard to Graal
Jiroxys7's Avatar
Join Date: Apr 2009
Posts: 343
Jiroxys7 will become famous soon enough
so if i needed to send a variable over to serverside to be calculated for a clientr.var, would i send a temp.var or a this.var? or something else?
__________________
MY POSTS ARE PRONE TO EDITS!
Reply With Quote
  #2  
Old 05-25-2010, 07:19 AM
salesman salesman is offline
Finger lickin' good.
salesman's Avatar
Join Date: Nov 2008
Location: Colorado
Posts: 1,865
salesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud of
Quote:
Originally Posted by Jiroxys7 View Post
so if i needed to send a variable over to serverside to be calculated for a clientr.var, would i send a temp.var or a this.var? or something else?
I'm not exactly the best teacher, so you probably want someone else to help you out, however I will try!

temp.variables are only accessible in the function where they are defined. For example,
PHP Code:
function someFunction() {
  
temp.foo 3.14159// define temp.foo in this function block
  
  
echo(temp.foo// echoes 3.14159

  
otherFunction(); // call a new function
}

function 
otherFunction() {
  echo(
temp.foo); // this will NOT echo anything, because temp.foo was not defined in this function
  
  // however, I can define an entirely new temp.foo, completely unrelated to the temp.foo in someFunction()
  
temp.foo "test";

Parameters passed to a function are also temp.vars and are only accessible within the function block.

this.variables on the other hand are assigned to the object in which they are defined (hence "this") and are accessible throughout the object

for example,
PHP Code:
function someFunction() {
  
this.foo "bar";
  
  echo(
this.foo); // echoes "bar"

  
otherFunction();
}

function 
otherFunction() {
  echo(
this.foo); // echoes "bar"

I can even access the variable from other objects as long as I have a reference to the object in which it was defined. Say this.foo was declared in a DBNPC called "MyNPC"...I can access the variable "foo" with the following statement from another NPC:
PHP Code:
// Another DB NPC

function inAnotherNPC() {
  echo(
MyNPC.foo); // echoes "bar"

It is important to note that a this.var defined on the serverside cannot be accessed on the clientside (or vice-versa). So how do you send data between the two? There are a few methods, but most notably, triggerServer() and triggerClient().

triggerServer() is called from the clientside and will invoke the event "onActionServerSide()" on the serverside. Alternatively, triggerClient() will invoke "onActionClientSide()" on the clientside.

Both require two parameters, and also allow an arbitrary (i think?) number of extra parameters.
  1. The first parameter will be the type of NPC you are triggering ("weapon", "gui", or "npc"). weapon and gui are interchangeable, and should be used for WNPCs, npc should be used for DB NPCs.
  2. The second is the name of the NPC

for example, I want to call a function in a weapon NPC on the serverside from the clientside of the same weapon:
PHP Code:
// invoked whenever triggerServer() is used on this weapon
function onActionServerSide(cmd) {
  
// "cmd" is a parameter that I specified in order to ensure that the trigger is the one I want
  
if (temp.cmd == "test") { // I sent "test" as a parameter from the clientside
    
myServersideFunction();
  }
}

//#CLIENTSIDE

function someFunction() {
  
triggerServer("weapon"this.name"test");


So to answer your question, you can send any type of variable you want as a parameter via triggerServer(). You can then assign the parameter on the serverside to a clientr.var, this.var, or pass it to another function...whatever you want. If this is confusing just ignore everything I said and wait for someone else to help you
__________________
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 10:41 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.