Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 06-16-2007, 02:12 AM
killerogue killerogue is offline
Registered Omega
killerogue's Avatar
Join Date: Apr 2006
Location: United States
Posts: 1,920
killerogue is on a distinguished road
Send a message via AIM to killerogue Send a message via MSN to killerogue
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. :[
__________________


REMEMBER, IF YOU REP ME, LEAVE A NAME!

Quote:
Originally Posted by haunter View Post
Graal admins don't die. They go to hell and regroup.
Quote:
Originally Posted by Inverness View Post
Without scripters, your graphics and levels wouldn't do anything but sit there and look pretty.
Reply With Quote
  #2  
Old 06-16-2007, 02:31 AM
JkWhoSaysNi JkWhoSaysNi is offline
Ruler of the graalaxy
Join Date: Feb 2005
Location: Great Britain
Posts: 488
JkWhoSaysNi is on a distinguished road
Send a message via ICQ to JkWhoSaysNi
had a similar problem:
http://forums.graalonline.com/forums...ad.php?t=74063

The objects you add have to be TStaticVar.
__________________

Coming soon (Hopefully:P)
Reply With Quote
  #3  
Old 06-16-2007, 02:34 AM
killerogue killerogue is offline
Registered Omega
killerogue's Avatar
Join Date: Apr 2006
Location: United States
Posts: 1,920
killerogue is on a distinguished road
Send a message via AIM to killerogue Send a message via MSN to killerogue
Ah, thanks Knight, it worked wonders. :]
__________________


REMEMBER, IF YOU REP ME, LEAVE A NAME!

Quote:
Originally Posted by haunter View Post
Graal admins don't die. They go to hell and regroup.
Quote:
Originally Posted by Inverness View Post
Without scripters, your graphics and levels wouldn't do anything but sit there and look pretty.
Reply With Quote
  #4  
Old 06-16-2007, 03:40 AM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
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 View Post
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.
__________________
Reply With Quote
  #5  
Old 06-16-2007, 01:39 PM
JkWhoSaysNi JkWhoSaysNi is offline
Ruler of the graalaxy
Join Date: Feb 2005
Location: Great Britain
Posts: 488
JkWhoSaysNi is on a distinguished road
Send a message via ICQ to JkWhoSaysNi
Well, I found different.

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

Coming soon (Hopefully:P)
Reply With Quote
  #6  
Old 06-16-2007, 01:58 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
Quote:
Originally Posted by Inverness View Post
Gui Controls have the controls array of all their child objects.
As well as the array of objects called players .
Reply With Quote
  #7  
Old 06-16-2007, 08:45 PM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
Quote:
Originally Posted by JkWhoSaysNi View Post
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?
__________________
Reply With Quote
  #8  
Old 06-16-2007, 08:52 PM
JkWhoSaysNi JkWhoSaysNi is offline
Ruler of the graalaxy
Join Date: Feb 2005
Location: Great Britain
Posts: 488
JkWhoSaysNi is on a distinguished road
Send a message via ICQ to JkWhoSaysNi
Quote:
Originally Posted by Inverness View Post
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 View Post
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); 
__________________

Coming soon (Hopefully:P)
Reply With Quote
  #9  
Old 06-16-2007, 09:04 PM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
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 -.-
__________________
Reply With Quote
  #10  
Old 06-16-2007, 09:34 PM
zokemon zokemon is offline
That one guy...
zokemon's Avatar
Join Date: Mar 2001
Location: Sonoma County, California
Posts: 2,925
zokemon is a jewel in the roughzokemon is a jewel in the rough
Send a message via ICQ to zokemon Send a message via AIM to zokemon Send a message via MSN to zokemon Send a message via Yahoo to zokemon
Quote:
Originally Posted by Inverness View Post
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.
__________________
Do it with a DON!
Reply With Quote
  #11  
Old 06-16-2007, 11:25 PM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
Quote:
Originally Posted by zokemon View Post
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.
__________________
Reply With Quote
Reply


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 08:05 PM.


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