Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 10-15-2011, 01:23 AM
Emera Emera is offline
Delterian Hybrid
Emera's Avatar
Join Date: Mar 2011
Location: Newcastle Upon-Tyne
Posts: 1,704
Emera is a jewel in the roughEmera is a jewel in the rough
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?
__________________
Reply With Quote
  #2  
Old 10-15-2011, 01:29 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
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.
__________________
Quote:
Reply With Quote
  #3  
Old 10-15-2011, 02:25 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Also, never use if (playertouchsme).
__________________
Reply With Quote
  #4  
Old 10-15-2011, 02:51 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Quote:
Originally Posted by cbk1994 View Post
Also, never use if (playertouchsme).
or any other flag that's now a function/event. (playerchats, playerenters, etc.)
__________________
Quote:
Reply With Quote
  #5  
Old 10-16-2011, 03:18 PM
MrDunne MrDunne is offline
Registered User
Join Date: Aug 2010
Posts: 38
MrDunne is on a distinguished road
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.
Reply With Quote
  #6  
Old 10-16-2011, 04:15 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by MrDunne View Post
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).
__________________
Reply With Quote
  #7  
Old 10-16-2011, 04:36 PM
MrDunne MrDunne is offline
Registered User
Join Date: Aug 2010
Posts: 38
MrDunne is on a distinguished road
Quote:
Originally Posted by cbk1994 View Post
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?
Reply With Quote
  #8  
Old 10-16-2011, 06:58 PM
Tolnaftate2004 Tolnaftate2004 is offline
penguin.
Join Date: Jul 2004
Location: Berkeley, CA
Posts: 534
Tolnaftate2004 is a jewel in the roughTolnaftate2004 is a jewel in the rough
Send a message via AIM to Tolnaftate2004
Quote:
Originally Posted by Emera View Post
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 View Post
... onCreated is called in the class when it's joined.
triggered
__________________
◕‿‿◕ · pfa · check yer syntax! · src

Killa Be: when i got that locker in 6th grade the only thing in it was a picture of a midget useing a firehose :/
Reply With Quote
  #9  
Old 10-16-2011, 07:10 PM
Emera Emera is offline
Delterian Hybrid
Emera's Avatar
Join Date: Mar 2011
Location: Newcastle Upon-Tyne
Posts: 1,704
Emera is a jewel in the roughEmera is a jewel in the rough
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!
__________________
Reply With Quote
  #10  
Old 10-16-2011, 08:11 PM
MrDunne MrDunne is offline
Registered User
Join Date: Aug 2010
Posts: 38
MrDunne is on a distinguished road
Quote:
Originally Posted by Emera View Post
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.
Reply With Quote
Reply


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 07:23 AM.


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