PDA

View Full Version : GScript for Dummies Guide to GS2 question.


maximus_asinus
08-03-2017, 01:01 PM
I'm reading the guide on GS2 and near the end he or she mentions objects. This part has me lost. What exactly is happening here?

temp.controlnpc = findnpc("Control-NPC"); //Creates an object references the Control-NPC
this.player_data = temp.controlnpc.player_data; //Copies data from the Control-NPC to the current NPC.
temp.controlnpc.onCreated(); //Executes the onCreated function through the Control-NPC

I can only guess what Control-NPC is. I see it listed on the server I am practicing on, but I have very limited rights so I can't open it up. I assume there is code inside, but at this point I am only guessing what this script is referencing.

maximus_asinus
08-03-2017, 06:17 PM
Okay after reading some of FP4's tutorial I am guessing temp.controlnpc = findnpc("Control-NPC") finds the object and this.player.data = temp.controlnpc.player_data pulls the value of player_data from the object? But what does temp.controlnpc.onCreated() do? Execute code listed in the onCreated() part of the Control-NPC? If so, how is this different than creating a class, using join, and calling a function that way?

Kamaeru
08-03-2017, 07:45 PM
Okay after reading some of FP4's tutorial I am guessing temp.controlnpc = findnpc("Control-NPC") finds the object and this.player.data = temp.controlnpc.player_data pulls the value of player_data from the object? But what does temp.controlnpc.onCreated() do? Execute code listed in the onCreated() part of the Control-NPC? If so, how is this different than creating a class, using join, and calling a function that way?
Control-NPC is an NPC, not a class.

BTW I learned a little from reading this.

maximus_asinus
08-03-2017, 10:55 PM
Control-NPC is an NPC, not a class.

BTW I learned a little from reading this.
FP4's tutorial is actually really helpful. I had no idea you could call functions from a variable. Also I now understand what the different variable prefixes do.

maximus_asinus
08-03-2017, 11:40 PM
Control-NPC is an NPC, not a class.
Yeah I realize that. I am just wondering what the difference of doing what was posted vs something like:


// Part of Class NPC called ControlNPC
function onControl() {
temp.control = player_data; // player_data defined earlier in the script
return temp.control;
}


function onCreated() {
join("ControlNPC");
}
//#CLIENTSIDE
function onPlayerChats() {
temp.foobar = onControl();
echo(temp.foobar);
}

But maybe I am not clear on the difference between an NPC and a Class. Or maybe I don't know what I'm talking about.

I am not by a computer so I don't know if this is 100% correct**

Kamaeru
08-04-2017, 03:05 AM
This is the best gs2 documentation I have found:

http://gswiki.wikidot.com/gs2-commands

This is the best for explaining how to script gs2:

http://gscript.graal.net/Index

But the best way to learn I have found that helped me the most was javascript lessons here:

http://www.freecodecamp.com