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 10-17-2009, 11:58 AM
scriptless scriptless is offline
Banned
Join Date: Dec 2008
Location: N-Pulse
Posts: 1,412
scriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to behold
array[0].name, not working?

I know there is a way but I can't seem to remember how I accomplished it before. What I am trying to do is something like this:

NPC Code:
array[0].name = "test";
player.chat = array[0].name;



But, it keeps returning 0.

Any thoughts would be nice.
Reply With Quote
  #2  
Old 10-17-2009, 12:05 PM
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
Quick guess:
I suppose "name" is a reserved word/var name. Try to use something else.
Reply With Quote
  #3  
Old 10-17-2009, 12:08 PM
scriptless scriptless is offline
Banned
Join Date: Dec 2008
Location: N-Pulse
Posts: 1,412
scriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to behold
Nope. Doesn't work.

I know this is possible. I think Devenio (sp?) helped me the first time about a year and a half ago maybe. *sigh*

Sometimes it does work tho. Like if I keep updating my script and changing stuff around then chaning it back to this it works.. No explination for why, but it doe, but not for long. THen it breaks again.

The only thing I think I can remember is something similar to this.

NPC Code:
with( test[0] ) {
a = "test";
}
player.chat = test[0].a;


Last edited by scriptless; 10-17-2009 at 12:28 PM..
Reply With Quote
  #4  
Old 10-17-2009, 12:39 PM
Twinny Twinny is offline
My empire of dirt
Twinny's Avatar
Join Date: Mar 2006
Location: Australia
Posts: 2,422
Twinny is just really niceTwinny is just really nice
Send a message via AIM to Twinny
PHP Code:
function onCreated()
{
  
this.array = {1,2,3};
  
this.array[0].var = "test";
  
  echo(
this.array[0].var);

Just got that working on Testbed. As Crow said, you won't be able to use 'name' since it's reserved...
Reply With Quote
  #5  
Old 10-17-2009, 12:39 PM
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
I tried this, and it works, even if I use "name". Are you doing this server- or clientside?

Edit: Twinny, it works with "name" as well. I just ran into something similar before, that's why I thought it wouldn't work (:
Reply With Quote
  #6  
Old 10-17-2009, 12:42 PM
scriptless scriptless is offline
Banned
Join Date: Dec 2008
Location: N-Pulse
Posts: 1,412
scriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to behold
Quote:
Originally Posted by Twinny View Post
PHP Code:
function onCreated()
{
  
this.array = {1,2,3};
  
this.array[0].var = "test";
  
  echo(
this.array[0].var);

Just got that working on Testbed. As Crow said, you won't be able to use 'name' since it's reserved...
I know it is possible without:

NPC Code:
this.array = {1,2,3};



I am trying this for an array of a size that is unknown. So I need to be able to add to the array as needed. Could I just reset the size each time I add a value?

I think I got it now.

PHP Code:
//#CLIENTSIDE
function onCreated()
{
  
this.array = new TStaticVar();
  
this.array[0].var = "test";

  
player.chat this.array[0].var;

Reply With Quote
  #7  
Old 10-17-2009, 12:46 PM
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
If temp.array[0] doesn't even exist yet, temp.array[0].name can't exist either.

Edit: Yea, static vars are your best shot I guess.
Reply With Quote
  #8  
Old 10-17-2009, 12:47 PM
Twinny Twinny is offline
My empire of dirt
Twinny's Avatar
Join Date: Mar 2006
Location: Australia
Posts: 2,422
Twinny is just really niceTwinny is just really nice
Send a message via AIM to Twinny
What do you mean by reset the size?

PHP Code:
function onCreated()
{
  
this.array = {1,2,3};
  
this.array[0].var = "test";
  
  echo(
this.array[0].var);
  
this.array.add(4);
  
this.array.add(5);
  
this.array.remove(4);
  echo(
this.array);
  echo(
this.array[0].var);

echos

PHP Code:
test
1
,2,3,5
test 
If the array will be unsorted, give your var a special tag. Thus when you want to update it, just go through the array in a loop until you hit the tag.
Reply With Quote
  #9  
Old 10-17-2009, 12:50 PM
scriptless scriptless is offline
Banned
Join Date: Dec 2008
Location: N-Pulse
Posts: 1,412
scriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to behold
What I am trying to do is. Skip the need for

NPC Code:
this.array = {1,2,3};



And just do:

PHP Code:
 this.array[#].value = "blah"; 
But to do it in a for loop that size changes. I may not know if I need {1, 2} or {1,2,3}.

Here is what I mean, kinda:

PHP Code:
//#CLIENTSIDE
function onCreated()
{
  for( 
i=0i<10i++) {
    
temp.array[i] = new TStaticVar();
    
withtemp.array[i] ) {
      
this.var = "test:" SPC i;
    }
  }
  
  
player.chat temp.array[1].var;

Which does not work obviously.
Reply With Quote
  #10  
Old 10-17-2009, 12:53 PM
Twinny Twinny is offline
My empire of dirt
Twinny's Avatar
Join Date: Mar 2006
Location: Australia
Posts: 2,422
Twinny is just really niceTwinny is just really nice
Send a message via AIM to Twinny
Sort of like,

PHP Code:
function onCreated()
{
  
temp.array.add(2);
  
temp.array.add("hi!");
  
temp.array.add("bogan");
  
  for (
t=0t<temp.array.size(); t++)
  if (
temp.array[t] == "hi!")
  {
    
thiso.pointer temp.array[t];
    
thiso.pointer.var = "woo";
    break;
  }
  echo(
this.pointer.var);

I think the index will have to have a non-null value before you can assign values to it unless you add an object instead.

[Edit]

Confirmed
PHP Code:
function onCreated()
{
  
temp.array[0] = "hi";
  
temp.array[1].var = "yes";
  echo(
temp.array[1].var);

doesn't work =(
Reply With Quote
  #11  
Old 10-17-2009, 12:58 PM
scriptless scriptless is offline
Banned
Join Date: Dec 2008
Location: N-Pulse
Posts: 1,412
scriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to behold
Kinda but not really.

This might help.

Instead of:
PHP Code:
temp.obj.name[0] = "bob";
temp.obj.name[1] = "eddy";
temp.obj.name[2] = "joe";
temp.obj.age[0] = "22";
temp.obj.age[1] = "23";
temp.obj.age[2] = "24"
I could use:
PHP Code:
withtemp.obj[i] ) {
this.name "name";
this.age "age";

I could then use my second example in a loop to assign each persons data in a much more easy to use manor. Because then all I would have to do to copy the data is copy what ever is at temp.obj[i].

As for the easily copy of the data I can worry about a function to do that if needed. But, do you see what I am saying?
Reply With Quote
  #12  
Old 10-17-2009, 01:04 PM
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
Let's try to find a different solution then What are you trying to achieve? There are surely more ways to do what you want to do.
Reply With Quote
  #13  
Old 10-17-2009, 01:11 PM
scriptless scriptless is offline
Banned
Join Date: Dec 2008
Location: N-Pulse
Posts: 1,412
scriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to behold
Basically.

Instead of:
PHP Code:
array[0][0] = "bananna";
array[
0][1] = 1;
array[
1][0] = "orange";
array[
1][1] = 5
This:
PHP Code:
with( array[0] ) {
this.food "bananna";
this.price 1;
}
with( array[1] ) {
this.food "orange";
this.price 5;

See how this is much easier to udnerstand? Using multi-demension arrays can be such a pain in the butt sometimes. I would MUCH rather have arrays like my second example. But of course using a loop so I would not have to repeat these lines of code a million times.

I dont even know if you can use my first example and try and copy array[0] to newarray[0].. Possible? dunno. But you can see here I am looking at the array as the object. And giving info about it names rather then numbers in a multi demensional array.

Think of it as, when you hold something in your hand. That item has details about it.. Height, width, weight, color, smell... etc Would it make sence to say this items 0 value is 100 px.. its 1 value is 120px to explain to someone that its demensions are 100x120 ?
Reply With Quote
  #14  
Old 10-17-2009, 01:18 PM
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, associative arrays would be a nice thing to have, eh? You are not bound to arrays though. Why don't you just use multiple static vars? You could even combine them in a bigger one, like this:
PHP Code:
temp.core = new TStaticVar();
temp.core.= new TStaticVar();
temp.core.= new TStaticVar();

temp.core.a.name "blah";
temp.core.b.name "bleh"
And so on.
Reply With Quote
  #15  
Old 10-17-2009, 01:21 PM
scriptless scriptless is offline
Banned
Join Date: Dec 2008
Location: N-Pulse
Posts: 1,412
scriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to behold
Basically. I want to make a simple inventory.

array[i].name to be the item. Were i represents the index of the item in inventory. Each appending name after it to represent that detail about the item.

This, however, works. But is there any simpler way to do such a task? I mean I dont see why I must assign a value using add(). =/

PHP Code:
//#CLIENTSIDE
function onCreated()
{
  
temp.obj = new TStaticVar();
  for( 
i=0i<10i++) {
    
temp.obj.add("");
    
withtemp.obj[i] ) {
      
this.var = "test:" SPC i;
    }
  }


  
player.chat temp.obj[1].var;

Does:
NPC Code:
temp.obj = new TStaticVar();



Reset the array???

Also, this does not work. Any thoughts?

PHP Code:
//#CLIENTSIDE
function onCreated()
{
  
temp.obj = new TStaticVar();
  
temp.obj2 = new TStaticVar();
  for( 
i=0i<10i++) {
    
temp.obj.add("");
    
withtemp.obj[i] ) {
      
this.var = "test:" SPC i;
    }
  }
  
temp.obj2 temp.obj[0];

  
player.chat temp.obj2.var;

Just wondering about the above. Why would that not work?

Last edited by scriptless; 10-17-2009 at 01:32 PM..
Reply With Quote
  #16  
Old 10-17-2009, 01:29 PM
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
I'm sure that this..
PHP Code:
temp.array = {}; 
..empties the array, if that's what you want.

Edit: Your last script doesn't work because you are trying to use the add() function although it does not exist. Careful, this only works on arrays. Neither temp.obj nor temp.obj2 is an array in your script.
Reply With Quote
  #17  
Old 10-17-2009, 01:37 PM
scriptless scriptless is offline
Banned
Join Date: Dec 2008
Location: N-Pulse
Posts: 1,412
scriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to behold
Add is working fine. I need temp.obj2 to point to the data I assign it to form temp.obj and i need this value in temp.obj2 to stay that data if I were to putnpc2.. =/
Reply With Quote
  #18  
Old 10-20-2009, 06:19 AM
scriptless scriptless is offline
Banned
Join Date: Dec 2008
Location: N-Pulse
Posts: 1,412
scriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to behold
Hey, back again. Here is what I got so far. But is there any way to use a function instead of having to use the 2 lines under //copy?

PHP Code:
//#CLIENTSIDE
function onCreated()
{
  
temp.obj = new TStaticVar();
  
temp.obj2 = new TStaticVar();
  
  for( 
i=0i<10i++) {
    
temp.obj.add("");
    
withtemp.obj[i] ) {
      
this.var = "test:" SPC i;
      
this.test "works:" SPC i;
    }
  }
  
  
//copy
  
temp.obj2.loadvarsfromarraytemp.obj[2].savevarstoarray(true) );
  
obj.test temp.obj2;
  
  
//test
  
player.chat obj.test.getdynamicvarnames();

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 11:14 PM.


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