View Single Post
  #14  
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