Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 08-17-2017, 09:12 AM
maximus_asinus maximus_asinus is offline
RIP DarkCloud_PK
Join Date: Oct 2001
Location: Canada
Posts: 3,727
maximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond repute
public function help

In one class named "block" I have this script:
Graal Script Code:
public function OrbSwitch() {
// actions

and in another class named "switch" I have this script:
Graal Script Code:
function onActionAHPHit() { // custom sword triggeraction
// actions
  
block.OrbSwitch();

Everything under onActionAHPHit() works but the public function isn't being triggered. Am I using the function wrong?
__________________
Save Classic!
Reply With Quote
  #2  
Old 08-17-2017, 09:28 AM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
Pretty much. If you want to use a function that's defined in a class, you'll have to join() that class first. The function also doesn't have to be "public". Public functions can be useful in weapons, though. Let's look at an excerpt of some Atlantis weapons.

-Weather:
Graal Script Code:
function onCreated() {
    
weather this;  // I love doing this stuff
}

public function 
GetWeather() {
    return 
this.sWeather;

-DayNight:
Graal Script Code:
function UpdateSymbols() {
    
// lots of code here
    
temp.we weather.GetWeather();
    
// a lot more code using the stuff we just got from -Weather

__________________
Reply With Quote
  #3  
Old 08-17-2017, 10:26 AM
maximus_asinus maximus_asinus is offline
RIP DarkCloud_PK
Join Date: Oct 2001
Location: Canada
Posts: 3,727
maximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond repute
I figured that was the problem. Thanks!

Unrelated but can you set a gani using a variable as a wildcard? Lets say I have a gani named "walk_true" and another called "walk_false".

Graal Script Code:
function onCreated() {
  
this.foobar = !this.foobar;
  
this.ani "walk_"@this.foobar;

I've tried this and I had no luck.
__________________
Save Classic!
Reply With Quote
  #4  
Old 08-17-2017, 11:59 AM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
Well, first off, you should be using setAni() instead. And then, this.foobar is also a boolean in this case. You should evaluate that to something yourself to avoid issues. (this.foobar ? '1' : '0'), for example.
__________________
Reply With Quote
  #5  
Old 08-17-2017, 06:51 PM
maximus_asinus maximus_asinus is offline
RIP DarkCloud_PK
Join Date: Oct 2001
Location: Canada
Posts: 3,727
maximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond repute
What is the difference between using this.ani and setAni()?

Also coming back to the original post, is it possible for two classes to communicate?

My example:

In the first class I have a switch that the player interacts with by swinging the sword. This class is supposed to tell the second class that it was hit. In the second class I have blocks that raise or lower depending on the status of the switch.

I'd rather keep them as separate classes to keep it neat, and I don't want to use triggeraction because I might have a room full of blocks and defining coordinates would be a pain. There must be a clean way to just do something like "triggerclass" or something.
__________________
Save Classic!
Reply With Quote
  #6  
Old 08-18-2017, 04:49 AM
maximus_asinus maximus_asinus is offline
RIP DarkCloud_PK
Join Date: Oct 2001
Location: Canada
Posts: 3,727
maximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond repute
I've exhausted my theories on how to get this to work outside of using a loop to check for a variable change (but that seems very inefficient and not at all what I want to do). Come one guys, someone must know if what I'm suggesting is possible. I've tried to search this on the forums but there is literally tens of thousands of results for my search terms, and about 99.999% of those results have nothing to do with what I am trying to do.

And if I wasn't clear my goal is for when I hit a switch belonging to Class A I want all the items in Class B to update.
__________________
Save Classic!
Reply With Quote
  #7  
Old 08-18-2017, 05:41 AM
maximus_asinus maximus_asinus is offline
RIP DarkCloud_PK
Join Date: Oct 2001
Location: Canada
Posts: 3,727
maximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond repute
I went back and tried public function again after reading a post by fp4 and got something that ALMOST works.

CLASS A
Graal Script Code:
//#CLIENTSIDE
function onActionAHPhit() { // custom sword hit detection
  
temp.foobar this.level.foobar;
  
temp.foobar.baz();

CLASS B
Graal Script Code:
//#CLIENTSIDE
function onCreated() {
  
this.setimg("block.png");
  
this.level.foobar this;
}
public function 
baz() {
  
this.chat "debug";

The problem is only the last NPC to join Class B will receive the update. If I could get around that I would be all set.
__________________
Save Classic!
Reply With Quote
  #8  
Old 08-18-2017, 11:35 AM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
Well, you already have the right idea with making object references available through the level object. Instead of just setting one (which will inevitably overwrite things if you have more than one block or whatever), maybe try storing them all in an array? I haven't tried this before. Should work, though.
__________________
Reply With Quote
  #9  
Old 08-18-2017, 07:03 PM
maximus_asinus maximus_asinus is offline
RIP DarkCloud_PK
Join Date: Oct 2001
Location: Canada
Posts: 3,727
maximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond repute
I am not sure how I would do that. I tried something like this.level.foobar.add(this); and this.level.foobar[0] = this; expecting this.level.foobar[0] to return the object but apparently it doesn't work like that. I can only guess you can't store objects in arrays. This is incredibly frustrating. I wish GS2 was better documented.

PS thanks for the input thus far Crow.
__________________
Save Classic!
Reply With Quote
  #10  
Old 08-18-2017, 09:00 PM
BigNews BigNews is offline
Registered User
BigNews's Avatar
Join Date: Feb 2015
Posts: 3
BigNews has a spectacular aura about
You'll probably want to do something like this:

Class A:

Graal Script Code:
//#CLIENTSIDE 
function onCreated()
  if (
this.level.listeners.index(this.id) == -1)
    
this.level.listeners.add(this.id);

public function 
baz()
  
this.chat "debug"
Class B:

Graal Script Code:
//#CLIENTSIDE 
function onActionAHPhit() {
  for (
temp.id this.level.listeners) {
    
findnpcbyid(temp.id).baz();
  }

Because when the level is updated, it still retains any variables stored on the level object beforehand, which can cause array values to contain non-existent objects.

--------

Alternatively if you want to store the objects and be safe between level updates you could do something like:

Class A:

Graal Script Code:
//#CLIENTSIDE 
function onCreated() {

  
temp.coord this."_" this.y;
  
temp.this.level.listenerCoords.index(temp.coord);

  if (
temp.== -1) {
    
this.level.listenerCoords.add(temp.coord);
    
this.level.listeners.add(this);
  }
  else
    
this.level.listeners[temp.i] = this;


Class B:

Graal Script Code:
//#CLIENTSIDE 
function onActionAHPhit() {
  for (
temp.listener this.level.listeners) {
    
temp.listener.baz();
  }

(which assumes NPC coordinates are always unique)

Last edited by BigNews; 08-18-2017 at 09:11 PM..
Reply With Quote
  #11  
Old 08-18-2017, 10:31 PM
maximus_asinus maximus_asinus is offline
RIP DarkCloud_PK
Join Date: Oct 2001
Location: Canada
Posts: 3,727
maximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond repute
And you just solved in 5 minutes what would have taken me 5 days.
__________________
Save Classic!
Reply With Quote
  #12  
Old 08-23-2017, 03:07 AM
maximus_asinus maximus_asinus is offline
RIP DarkCloud_PK
Join Date: Oct 2001
Location: Canada
Posts: 3,727
maximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond repute
I'm pretty desperate for help on this. I'm in over my head.

I'm trying to sync the blocks with everyone in the level. My first guess was to use triggerServer or triggerAction but I can get neither of those to work inside of a class (I've since read that triggerServer doesn't work in local or class NPCs without a hacked workaround).

I thought something like this would work, but no dice on this as well. I just can't grasp what I'm doing wrong.

Graal Script Code:
function onActionFoo () { 
// also tried onActionServerSide() when using 0,0 as triggerAction coordinates.
  
echo("bar");
}

//#CLIENTSIDE
function onCreated() {
  
setshape(1,32,32);
}

function 
onPlayerChats() {
  if (
player.chat == "foo") {
    echo(
"foo");
    
triggerAction(x,y"Foo"NULL);
  }

I'm circling back around to having to use a timeout in the blocks, but I feel like that is a hack option and could cause lag if I had a level with dozens of blocks inside all with a nested loop.
__________________
Save Classic!
Reply With Quote
  #13  
Old 08-23-2017, 07:50 AM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
Try using setshape() on the serverside as well.
__________________
Reply With Quote
  #14  
Old 08-24-2017, 05:32 AM
maximus_asinus maximus_asinus is offline
RIP DarkCloud_PK
Join Date: Oct 2001
Location: Canada
Posts: 3,727
maximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond repute
That makes perfect sense and worked perfectly. I've successfully synced with players in the level.

(yet another post)

What are the limitations of using level variables on a GMAP? I remember reading that the player only loads a 3x3 chunk of the GMAP. Providing that this is true, does the level variable continue to sync past this point?

If not then I need a solution for saving my switch variable. My guess is that I would have to use a DB NPC (another thing I have no experience with. Yay). If I save each quest set with a unique prefix is there a simple way to catch the level prefix so I can try to make each set of switches unique?

I'm thinking of designing it something like:

Graal Script Code:
// database variables
// true means hit, false means not hit
this.quest dungeon1_dungeon2_dungeon3_
this
.switch = truefalsefalse 
Graal Script Code:
  // get level prefix
with(findNPC(Database)) {
  
// check for position of prefix in this.quest
  // save position of prefix and then check corresponding location in this.switch for switch status.
  // change the found value in this.switch

Any help on using a database in this context or finding the level prefix would be appreciated.
__________________
Save Classic!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 12:34 PM.


Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
Copyright (C) 1998-2008 Linux cyberjoueurs All Rights Reserved.