Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Public Function Issue (https://forums.graalonline.com/forums/showthread.php?t=134264804)

Emera 10-15-2011 01:23 AM

Public Function Issue
 
Hello! I am trying to create a real simple public function to replace the already complicated quest icon system I made on lexia. Here is what I want to do. I want to create a public function in my npc class named, icon...
PHP Code:

public function QuestIcon(icon_text) {
  if (
playertouchsme) {
    
say2(icon_text);
  }


I am getting no success though when joining the class to the npc...
PHP Code:

join("icon"

then using the function...
PHP Code:

QuestIcon("My name is bob"); 

Here is what I am doing...
PHP Code:

function onCreated() {
  
join("icon");
}
if (
playertouchsme) {
icon.QuestIcon("MOO");


Anybody got any ideas?

fowlplay4 10-15-2011 01:29 AM

I don't think you understand what you're actually trying to do, what public functions are for, or how classes work.

Perhaps this is what you're trying to do:

Level NPC:

PHP Code:

function onCreated() {
  
this.quest_text "My name is bob";
  
join("icon");


class: icon

PHP Code:

function onPlayerTouchsMe() {
  
say2(this.quest_text);


A public function is for allowing other scripts to use the function remotely. I.e:

Level NPC A:

PHP Code:

function onCreated() {
  
this.level.cat this;
}

public function 
meow() {
  echo(
"Meow");


Level NPC B:

PHP Code:

function onCreated() {
  if (
this.level.cat == NULL) {
    
waitfor(this"LetCatLoad"0.05);
  }
  
temp.cat this.level.cat;
  
temp.cat.meow();


A class basically pastes code/functions into an NPC, onCreated is called in the class when it's joined.

cbk1994 10-15-2011 02:25 AM

Also, never use if (playertouchsme).

fowlplay4 10-15-2011 02:51 AM

Quote:

Originally Posted by cbk1994 (Post 1670926)
Also, never use if (playertouchsme).

or any other flag that's now a function/event. (playerchats, playerenters, etc.)

MrDunne 10-16-2011 03:18 PM

It's probably useful to point out why the above two posts are true:

There was a previous version of GScript which was less powerful than the current. The current language retained backwards compatibility so that older scripts wouldn't completely break. It's bad practice to use the old version whilst the new one is available.

I think a simple analogy works here. When the PS2 was released, it was possible to play PS1 games on it, which was great because many people still had PS1 games they loved to play. The PS1 games were ugly in comparison to their PS2 counterparts and they are rarely played nowadays. Folk that still do are are either looking for nostalgia (a percentage of which become disappointed fairly quickly) or they picked up an older PS1 version of a PS2 game on eBay by accident. The latter type gets ridiculed from their peers for mistakingly buying and playing the older version of the game.

The default level editor is the PS1, a rented server a PS2, GScript 1 is an old PS1 game and GScript 2 is a PS2 remaking of the same game. It should be obvious from here!

I think at this point in time Graal is still waiting for its PS3? Some would argue a different type of console altogether.

cbk1994 10-16-2011 04:15 PM

Quote:

Originally Posted by MrDunne (Post 1670977)
I think at this point in time Graal is still waiting for its PS3? Some would argue a different type of console altogether.

Graal isn't in desparate need of a new scripting language. GS2 has plenty of flaws, but it needs changes, not to be completely thrown out.

Stefan was experimenting with JavaScript as a serverside language, though, but I haven't heard anything about it in the past year. If JS was used, it might be possible for him to use an existing JavaScript engine like V8 (which uses JIT compilation) for massive speed improvements (not that they're really needed on serverside).

MrDunne 10-16-2011 04:36 PM

Quote:

Originally Posted by cbk1994 (Post 1670979)
Graal isn't in desparate need of a new scripting language. GS2 has plenty of flaws, but it needs changes, not to be completely thrown out.

Stefan was experimenting with JavaScript as a serverside language, though, but I haven't heard anything about it in the past year. If JS was used, it might be possible for him to use an existing JavaScript engine like V8 (which uses JIT compilation) for massive speed improvements (not that they're really needed on serverside).

This was simply speculation. I haven't been back long enough to know the sentiments towards GS2 these days. I remember Inverness was pretty heavy on making all scripters Pythonistas.

I'd love to know more about that. Speed improvements are the last thing on the list here. CoffeeScript perhaps?

Tolnaftate2004 10-16-2011 06:58 PM

Quote:

Originally Posted by Emera (Post 1670924)
Hello! I am trying to create a real simple public function to replace the already complicated quest icon system I made ...

PHP Code:

public function QuestIcon(icon_text) {
  
//if (playertouchsme) { // this is an event, not a flag and 
                          // won't be executed in this context
    // do stuff
  //}


PHP Code:

function onPlayerTouchsMe() { // preferred method
  
icon::QuestIcon("MOO");     // you can specify the class name thusly 
                              // (if you want to do so at all)


Quote:

Originally Posted by fowlplay4 (Post 1670925)
... onCreated is called in the class when it's joined.

triggered

Emera 10-16-2011 07:10 PM

Quote:

There was a previous version of GScript which was less powerful than the current. The current language retained backwards compatibility so that older scripts wouldn't completely break. It's bad practice to use the old version whilst the new one is available.
I knew this already, I was being lazy and saving me a few seconds. Sorry lol. Thank you to everybody that helped though!

MrDunne 10-16-2011 08:11 PM

Quote:

Originally Posted by Emera (Post 1670994)
I knew this already, I was being lazy and saving me a few seconds. Sorry lol. Thank you to everybody that helped though!

Please refer to the last part of my analogy:

Quote:

The latter type gets ridiculed from their peers for mistakingly buying and playing the older version of the game.


All times are GMT +2. The time now is 07:05 AM.

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