Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Multidimensional array problem (https://forums.graalonline.com/forums/showthread.php?t=61094)

Silent 09-08-2005 11:29 PM

Multidimensional array problem
 
I have a class named silent_example which is joined to the player at logon, which is as follows:


PHP Code:

function onCreated() {
  echo(
"silent_example: Joined to " player.account);
  
player.clientr.example = new[2][2];
}

public function 
example_run() {
  echo(
"silent_example: Setting array value");
  
player.clientr.example[1][1] = 5;


Basically, the "player.clientr.example[1][1] = 5;" isn't doing anything. I've also tried player.clientr.example.replace(1,{0,5}) and player.clientr.example[1].replace(1,5) - nothing seems to work.

The array is being created fine, I can add to the array fine, both echos are working - I just can't edit the values from inside that public function. Any ideas?


Edit: Uh. Okay. That line doesn't work inside the onCreated either. What the hell?

ForgottenLegacy 09-09-2005 12:40 AM

You can't have a clientr string starting from the player object I guess. o-o Remove the player object and it should work.

Silent 09-09-2005 12:54 AM

Quote:

Originally Posted by ForgottenLegacy
You can't have a clientr string starting from the player object I guess. o-o Remove the player object and it should work.

Tried that, makes no difference

ForgottenLegacy 09-09-2005 05:53 AM

Hmm, okay then. Are you doing this inside of a NPCw? Because, for what I know, NPCws cannot read onCreated() serverside.

Silent 09-09-2005 09:44 AM

Quote:

Originally Posted by ForgottenLegacy
Hmm, okay then. Are you doing this inside of a NPCw? Because, for what I know, NPCws cannot read onCreated() serverside.

Re-read the first post, please x_x. It's a class joined to the player, and the function is called very simply from a weapon:
PHP Code:

function onActionserverside() {
  if (
params[0] == "test"player.example_run();
}

//#CLIENTSIDE

if (weaponfired) {
  
triggeraction x,y,serverside,Silent/Example,test;



Admins 09-09-2005 03:11 PM

Have you tried to do this.clientr.example[1][1] = 5; ? The "player" variable might not exist.

Silent 09-09-2005 11:45 PM

Quote:

Originally Posted by Stefan
Have you tried to do this.clientr.example[1][1] = 5; ? The "player" variable might not exist.

That doesn't work either :frown:
You can look at the scripts for yourself on ProjectR, if you like

ForgottenLegacy 09-10-2005 03:22 AM

Does anything else from the class work? It might be that the player itself isn't joining the class or something. I honestly don't know.

Note: I don't know if onCreated() would be called when a player joins a class. o-o How about... join the class and call a public function afterwards?

Silent 09-10-2005 12:56 PM

Quote:

Originally Posted by ForgottenLegacy
Does anything else from the class work? It might be that the player itself isn't joining the class or something. I honestly don't know.

Once again, TGC, read the first post. "both echos are working"

Ajira 09-10-2005 05:13 PM

Hmm, we had a similar problem like this. Try putting the echo() AFTER initializing the array etc.

calani 09-10-2005 10:06 PM

yay for quirks! o.o
and yay for my vip running out unexpectedly -.- (see missing sig)

Silent 09-11-2005 01:04 AM

Quote:

Originally Posted by Ajira
Hmm, we had a similar problem like this. Try putting the echo() AFTER initializing the array etc.

It's still only initializing the array and not changing the value. I tried removing the echo completely too, no luck (also retried this.clientr. etc) :frown:

Skyld 09-13-2005 12:36 AM

If you are joining a class to a player, would you use a different object (thiso. maybe, not sure) to get focus on the player?

Quote:

Originally Posted by calani
yay for quirks! o.o
and yay for my vip running out unexpectedly -.- (see missing sig)

Relevance, please.

Silent 09-21-2005 12:25 AM

Quote:

Originally Posted by Skyld
If you are joining a class to a player, would you use a different object (thiso. maybe, not sure) to get focus on the player?

Tried, failed. Heck, I've tried every object combination I could think of, and the value still won't change. I was hoping someone would've figured this out while I was without internet access, but I guess not x_x

Sure, there are other ways to do it, but this would be the most efficient and I see no reason why this way doesn't work. Bleh.

Ibonic 09-22-2005 01:48 PM

It does appear to be doing something: assigning the value, at least temporarily.


NPC Code:

player.clientr.example = new[2][2];
player.clientr.example[1][1] = 5;

echo(player.clientr.example[1][1]);



But when viewing the player attributes it shows as: clientr.example="0,0","0,0" -- that part is unexpected. It also loses the value when the player disconnects (or maybe even sooner), which is almost definitely related to it not setting the attribute variable correctly. As stated already, it doesn't make a difference whether you do or don't use the "player variable", or even the clientr/client ones for that matter.



As an extra note, it works fine if you use something like this in a NPC (for example)

NPC Code:

function onCreated() {
this.example = new[2][2];
this.example[1][1] = 5;

}



That shows: example="0,0","0,5" in the flags, as expected.

---

Maybe that will help (Stefan?) debug a bit, if nothing else.


All times are GMT +2. The time now is 01:19 AM.

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