Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   writing to an npc flag from class? (https://forums.graalonline.com/forums/showthread.php?t=134264619)

gaben 09-23-2011 11:46 PM

writing to an npc flag from class?
 
i've done it before, but for some reason it just won't work properly

npc vardump:

PHP Code:

Variables dump from npc boolean

boolean
.typeSYSTEM
boolean
.scripterboolean
boolean
.levelonlinestartlocal.nw

Attributes
:
boolean.image
boolean.scriptsize0
boolean
.visibility flagsvisible
boolean
.id1014
boolean
.sprite2
boolean
.head
boolean.xprecise0
boolean
.yprecise0

this
.-Flags
boolean
.vote=12 

class:

PHP Code:

function onCreated(){
  
boolean.vote[0] = 1;
  
sendtonc(boolean.vote[0]); // outputs 12 instead of 1


help is appreciated

ffcmike 09-23-2011 11:51 PM

Quote:

Originally Posted by gaben (Post 1668944)
i've done it before, but for some reason it just won't work properly

npc vardump:

PHP Code:

Variables dump from npc boolean

boolean
.typeSYSTEM
boolean
.scripterboolean
boolean
.levelonlinestartlocal.nw

Attributes
:
boolean.image
boolean.scriptsize0
boolean
.visibility flagsvisible
boolean
.id1014
boolean
.sprite2
boolean
.head
boolean.xprecise0
boolean
.yprecise0

this
.-Flags
boolean
.vote=12 

class:

PHP Code:

function onCreated(){
  
boolean.vote[0] = 1;
  
sendtonc(boolean.vote[0]); // outputs 12 instead of 1



To write "vote[0]", vote would need to be initialized as an array first, such as:

PHP Code:

//boolean.vote = new[array size];
boolean.vote = new[2]; 

or

PHP Code:

boolean.vote = {NULLNULL}; 


gaben 09-24-2011 12:04 AM

For whatever reason I'm having trouble just adding to the array.

PHP Code:

function onPlayerChats(){
  if(
player.chat == "/b"){
   
boolean.vote = new[boolean.vote.size() + 1]; 
   
boolean.vote[this.boolean.vote.size() + 1] = 45;
   
player.chat boolean.vote[boolean.vote.size()];
  }


Will return 45 once, the other values are NULL. Other than that, it works quite nicely.

Crow 09-24-2011 12:26 AM

The new[] keyword will create a completely new array. You can't expand existing arrays with it. Also, you should use the array size minus one when assigning something to the last index/field, since it starts at 0.

Not sure if it's necessary, but I always create arrays with a dynamic size like this:
PHP Code:

temp.array = {};
temp.array = new[]; // I believe this is also possible 

You're also missing some this. prefixes in your code (that, or you got one where you don't want one).

gaben 09-24-2011 12:27 AM

Haha, yeah. I'll try that.

gaben 09-24-2011 03:29 PM

PHP Code:

  boolean.vote = {player.account};
  
player.chat boolean.vote[boolean.vote.size() - 1]; 

How would I make boolean.vote = {}; expand?

Crow 09-24-2011 03:47 PM

You can use temp.array.add(element).

gaben 09-24-2011 04:14 PM

ok cool


All times are GMT +2. The time now is 02:21 PM.

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