Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Raelyn's Big Book of Scripting Questions. (https://forums.graalonline.com/forums/showthread.php?t=85091)

Raelyn 04-29-2009 03:52 PM

Quote:

Originally Posted by Chompy (Post 1487600)
You'd have to join that class to use it's content.

Lets say this is a class called fibonacci:

PHP Code:

function fib(n) {
  return (((
1+5^0.5)/2)^- ((1-5^0.5)/2)^n)/(5^0.5)



To use that function, I would have to do:

PHP Code:

function onCreated() {
  
join("fibonacci");

  echo(
fib(7)); // 13



Ok, thanks.

Deas_Voice 04-29-2009 05:11 PM

one thing i always wondered when it comes to join(),
should i join it on serverside or clientside?
or even both?

Chompy 04-29-2009 05:19 PM

Quote:

Originally Posted by Deas_Voice (Post 1487613)
one thing i always wondered when it comes to join(),
should i join it on serverside or clientside?
or even both?

Depends on where you'll be using the class' content.

Deas_Voice 04-29-2009 05:42 PM

Quote:

Originally Posted by Chompy (Post 1487614)
Depends on where you'll be using the class' content.

both sides.
sometimes clientside or serverside.

napo_p2p 04-29-2009 07:25 PM

Quote:

Originally Posted by Deas_Voice (Post 1487616)
both sides.
sometimes clientside or serverside.

If you join it serverside, then both clientside and serverside parts of the class will work. If you join it clientisde, then only the clientside part of the class will work.

fowlplay4 04-29-2009 08:53 PM

I've noticed on the clientside if you join a class clientside you can't use the functions from the class right away.

ex:

PHP Code:

//class: whatever
//#CLIENTSIDE
function somefunc() {
  echo(
"!");


Then doing following..

PHP Code:

//#CLIENTSIDE
function onCreated() {
  
join("whatever");
  
somefunc(); // the somefunc in the class would not actually be called..
  
this.trigger("WildEvent"""); // so I would use a trigger..
}

function 
onWildEvent() {
  
somefunc(); // and ! would be displayed in F2



napo_p2p 04-29-2009 09:16 PM

Quote:

Originally Posted by fowlplay4 (Post 1487659)
I've noticed on the clientside if you join a class clientside you can't use the functions from the class right away.

ex:

PHP Code:

//class: whatever
//#CLIENTSIDE
function somefunc() {
  echo(
"!");


Then doing following..

PHP Code:

//#CLIENTSIDE
function onCreated() {
  
join("whatever");
  
somefunc(); // the somefunc in the class would not actually be called..
  
this.trigger("WildEvent"""); // so I would use a trigger..
}

function 
onWildEvent() {
  
somefunc(); // and ! would be displayed in F2



That's weird. Have you tried:
PHP Code:

whatever::somefunc(); 

??

cbk1994 04-29-2009 09:21 PM

It might take a minute to join, I've had trouble with that before as well.

fowlplay4 04-30-2009 12:28 AM

Quote:

Originally Posted by napo_p2p (Post 1487661)
That's weird. Have you tried:
PHP Code:

whatever::somefunc(); 

??

Just tried it, it only happens when you login/connect though, not when you update the script.

My above script didn't work with the trigger, however this worked fine and isn't noticable.

PHP Code:

//#CLIENTSIDE
function onCreated() {
  
join("whatever");
  
whatever::somefunc(); // the somefunc in the class would not actually be called..
  
this.scheduleevent(0.1"WildEvent"""); // so I would use a trigger..
}

function 
onWildEvent() {
  
somefunc(); // and ! would be displayed in F2


So I'd recommend joining serverside if you don't want to deal with the workaround above..

PHP Code:

function onCreated() {
  
join("whatever");
}
//#CLIENTSIDE
function onCreated() { 
  
somefunc(); // the somefunc in the class is called.



napo_p2p 04-30-2009 12:43 AM

You know, now that I think of it, it's requesting the script from the server when you call join(), which results in a small delay.

So, yea. It's easiest just to do all joins serverside.

xXziroXx 04-30-2009 12:38 PM

Jerret, you're actually missing something.

It's not being updated on clientside when you join it clientsided, true. But it's also not updated clientsided if you join it serversided. Note that sometimes both works, sometimes they don't - and when it doesn't work, it's updated if you reconnect with your client.

This is why I never "release" an updated clientsided class before manually reconnecting all current clients to ensure that they all got the update.

Raelyn 04-30-2009 08:26 PM

Ok, maybe I should ask this differently.. I wrote these scripts in GS1, but now I want to put them on my server, so can they be converted to GS2 easier with syntax changes? Or do I have to re-write them entirely?

napo_p2p 04-30-2009 08:51 PM

Quote:

Originally Posted by Raelyn (Post 1487919)
Ok, maybe I should ask this differently.. I wrote these scripts in GS1, but now I want to put them on my server, so can they be converted to GS2 easier with syntax changes? Or do I have to re-write them entirely?

You might get away with just putting the GS1 script up, but it's good practice to use only GS2 online.

You can mostly go line-by-line and make a direct change from GS1->GS2.

If you haven't checked it out already:
http://wiki.graal.net/index.php/Creation/Dev/GS1_To_GS2

That article gives a pretty good overview of the types of changes you need to make.

Raelyn 04-30-2009 09:27 PM

Quote:

Originally Posted by napo_p2p (Post 1487929)
You might get away with just putting the GS1 script up, but it's good practice to use only GS2 online.

You can mostly go line-by-line and make a direct change from GS1->GS2.

If you haven't checked it out already:
http://wiki.graal.net/index.php/Creation/Dev/GS1_To_GS2

That article gives a pretty good overview of the types of changes you need to make.

Ok, well for displaying showtext I presume this is the GS2 equivalent of what I have done for my hud.

PHP Code:

function onCreated() {
  
temp.= {55};
  
  
temp.txt "HP:" clientr.player_hp "/" clientr.player_hpmax;
  
temp.showtext(200temp.p[0], temp.p[1], "Arial""b"temp.txt);
  
temp.i.layer 4;

  
temp.txt "MP:" clientr.player_mp "/" clientr.player_mpmax;
  
temp.showtext(201temp.p[0], temp.p[1] + 20"Arial""b"temp.txt);
  
temp.i.layer 4;


As far as I can tell, this works the same, but I don't understand "temp.p" and "temp.i", "temp.i.layer". I presume temp.i.layer is the same as changeimgvis, but what I don't understand is why the text being on layer 4 works, when I thought only 5 and up works for the screen instead of the playing field?

This script is something another scripter made/posted on my RC and I'm trying to learn off it and/or convert it to match what I have done in GS1, since it seems nearly identical but with strange syntax differences.

This really confuses me as to why everyone says "GS2 is easier to understand" or "GS2 makes more sense" because GS1 makes sense to me, but looking at this stuff, I am like.. what?!

Raelyn 04-30-2009 09:35 PM

Quote:

Originally Posted by Chompy (Post 1487600)
You'd have to join that class to use it's content.

Lets say this is a class called fibonacci:

PHP Code:

function fib(n) {
  return (((
1+5^0.5)/2)^- ((1-5^0.5)/2)^n)/(5^0.5)



To use that function, I would have to do:

PHP Code:

function onCreated() {
  
join("fibonacci");

  echo(
fib(7)); // 13



Ok, so if I take all my functions from my base system script, and make the classes all functions, I can just go through and replace all the functions listed in the script with:

PHP Code:

function onCreated() {
join("class_name");


Is that right? What is the echo? And will GS1 and GS2 mix? It seems like they mix, but only that GS2 doesn't work offline.. is that right?


All times are GMT +2. The time now is 05:41 PM.

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