Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Objects into Arrays using Add()? (https://forums.graalonline.com/forums/showthread.php?t=74614)

killerogue 06-16-2007 02:12 AM

Objects into Arrays using Add()?
 
Hmm, I was working a multiple object arrays and such. When I came across a problem. Using add to add objects to and array when they are returned from a function. Is there a problem here? It's worked before. :[

SERIALIZE FUNCTION
PHP Code:

public function deserialize(stringvars) {
  
temp.list = 0;
  
temp.sObj 0;
  
temp.array = 0;
  
temp.0;
  
  array = 
string.tokenize(":");
  list = 
Mud.(@ vars);

  for (
0< list.size(); i++) {
    
makevar("sObj." @ list[i]) = array[i];
  }
  return 
makevar("sObj");


Returns the vars and the values perfectly when using echo and any var of sObj. However (and I have tried it without the makevar()), when I try to add it through array add in a function inside a different script....


PHP Code:

public function createObjects() {
  
join("serialize");
  
  
temp.file 0;
  
temp.0;
  
temp.0;
  
temp.0;
  
temp.obj 0;
  
temp.obj2 0;
  
temp.var = 0;
  
temp.var2 0;
  
temp.var3 0;
  
  
plyr findPlayer(this.account);
  
obj makevar("MudPlayer_" this.account);
  
obj.abilitylist.clear();
  
obj.spelllist.clear();
  
obj.skilllist.clear();
  
  
//Abilities
  
for (0obj.abilities.size(); a++) {
    
file.loadVars("mud/" obj.abilities[a] @ ".arc");
    
obj2 NULL;
    
obj2 = new TStaticVar();
    
    for (var : 
file.getDynamicVarNames()) {
      
makevar("obj2." @ var) = makevar("file." @ var);
    }
    
obj.abilitylist.add(makevar("obj2"));
    
obj.abilitylist[a].join("mud_object_ability");  
    
obj.abilitylist[a].effectlist.clear();
    
    for (
var2 obj.abilitylist[a].effects) {
      
obj.abilitylist[a].effectlist.add(deserialize(var2[1], "effectvars"));
      echo (
obj.abilitylist[a].effectlist[a].magnitude);
      
obj.abilitylist[a].effectlist[a].join("mud_object_effect");
    }
  }


Does not add the object to the array and no vars are returned or vals. :[

JkWhoSaysNi 06-16-2007 02:31 AM

had a similar problem:
http://forums.graalonline.com/forums...ad.php?t=74063

The objects you add have to be TStaticVar.

killerogue 06-16-2007 02:34 AM

Ah, thanks Knight, it worked wonders. :]

Inverness 06-16-2007 03:40 AM

Stan thats not a real object you're making. And why are you doing makevar("obj2")?

obj2 is already a complete variable name.

You would simply use: obj.abilitylist.add(obj2);
Quote:

Originally Posted by JkWhoSaysNi (Post 1318409)
had a similar problem:
http://forums.graalonline.com/forums...ad.php?t=74063

The objects you add have to be TStaticVar.

Uh, no. Any objects can be added to an array, Gui Controls have the controls array of all their child objects.

JkWhoSaysNi 06-16-2007 01:39 PM

Well, I found different.

My script just sopped working but changing the object to a TStaticVar fixed it.

Twinny 06-16-2007 01:58 PM

Quote:

Originally Posted by Inverness (Post 1318430)
Gui Controls have the controls array of all their child objects.

As well as the array of objects called players :D.

Inverness 06-16-2007 08:45 PM

Quote:

Originally Posted by JkWhoSaysNi (Post 1318535)
Well, I found different.

My script just sopped working but changing the object to a TStaticVar fixed it.

You seem to think varname.varname always means its an object, it doesn't, Graal is just compensating for bad scripting and that GS1 crap.

Personally I wish there was a serveroption to remove all GS1 compatibility, it would maybe stop some people from spewing crap like "GS1 is more logical like GS2", wtf?

JkWhoSaysNi 06-16-2007 08:52 PM

Quote:

Originally Posted by Inverness (Post 1318655)
You seem to think varname.varname always means its an object, it doesn't, Graal is just compensating for bad scripting and that GS1 crap.

Personally I wish there was a serveroption to remove all GS1 compatibility, it would maybe stop some people from spewing crap like "GS1 is more logical like GS2", wtf?

Sorry i had remembered wrongly, checking my thread, it's the array that has to be TStaticVar.

Quote:

Originally Posted by Me in the other thread (Post 1310205)
I figured it out.

For an array to store objects it must be a TStaticVar;

PHP Code:

channel = new TStaticVar();
channel.join("chat_channel");
channel.create(topicownerchannelname);

//Doesnt work: 
test.add(channel);
echo(
test[0].channelname); 


//works:
test2 = new TStaticVar();
test2.add(channel);
echo(
test2[0].channelname); 



Inverness 06-16-2007 09:04 PM

TGraalVar Types:
0 = Numeric
1 = String
2 = Object
3 = Array

As you can see, Objects and Arrays aren't quite the same.
The only reason the second part worked is because you initialized test2 before trying to add to it, I don't see this for the first part.

Arrays themselves are a type of object (TGraalVar) so I see no reason why you need to make it an object beforehand. Just make sure its initialized 'varname = 0;' will do the trick.

Here is an example that works:
PHP Code:

function onCreated() {
  
temp.object 0;
  
temp.array = 0;
  
  
object = new TStaticVar();
  
object.testvariable "ZOMG!";
  
  array.
add(object);
  echo(array[
0].testvariable);


Edit: Let me correct my statement, you're messing up somewhere because I know that variables are automatically initialized if Graal can't find one for what you're trying to do.
PHP Code:

function onCreated() {
  
temp.object 0;
  
//temp.array = 0;
  
  
object = new TStaticVar();
  
object.testvariable "ZOMG!";
  
  
temp.array.add(object);
  echo(array[
0].testvariable);


Stop trying to make me doubt my knowledge -.-

zokemon 06-16-2007 09:34 PM

Quote:

Originally Posted by Inverness (Post 1318655)
You seem to think varname.varname always means its an object, it doesn't, Graal is just compensating for bad scripting and that GS1 crap.

Personally I wish there was a serveroption to remove all GS1 compatibility, it would maybe stop some people from spewing crap like "GS1 is more logical like GS2", wtf?

It's not bad scripting... If I want to have a dot in my variable name, I shall!
I don't see how it has to do with GS1 at all though.

Inverness 06-16-2007 11:25 PM

Quote:

Originally Posted by zokemon (Post 1318671)
It's not bad scripting... If I want to have a dot in my variable name, I shall!
I don't see how it has to do with GS1 at all though.

GS1 wasn't really object-based so dots didn't matter as much. Dots are used for changing object scope mainly in many languages and in GS2 which is why its bad to use them in variable names. Other languages (Java, C++) don't compensate for that and you would simply get an error if you tried.


All times are GMT +2. The time now is 08:19 PM.

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