Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Array Copying Problems (https://forums.graalonline.com/forums/showthread.php?t=73340)

Inverness 04-07-2007 09:15 PM

Array Copying Problems
 
READ MY POST BEFORE YOU MAKE YOURSELF LOOK STUPID

Ok, heres a little script thats part of the new mud system I'm working on.
PHP Code:

public function loadObject() {
  
temp.file 0;
  
temp.vars 0;
  
temp.0;
  
temp.0;
  
temp.0;
  
  
file = new TStaticVar();
  
file.loadvars(format("%s/%s/%s.txt"MudControl.mudpaththis.mudtypethis.mudid));
  
MudControl.loadRefs(file);
  echo(
"1:" file.muditems[0].mudid);
  echo(
"2:" file.muditems[1].mudid);
  
vars file.getVarNames();
  
vars.remove("mudid");
  
vars.remove("mudtype");
  
  for (
0vars.size(); ++) {
    
//if (file.(@ vars[i]).type() != 3) {
      
this.(@ vars[i]) = file.(@ vars[i]);
    
//}
    //else {
    //  s = file.(@ vars[i]).size();
    //  this.(@ vars[i]) = new [s];
    //  for (e = 0; e < s; e ++) {
    //    this.(@ vars[i])[e] = file.(@ vars[i])[e];
    //  }
    //}
  
}
  echo(
"3: " this.muditems[0].mudid);
  echo(
"4: " this.muditems[1].mudid);
  
file.destroy();
  
triggerAll("onLoadedObject"null);


Now heres my problem, when an object is loaded it contains reference strings like ref:item:20010 and ref:item:20011 which were the two objects I was using for this test. Now the MudControl parses all these strings and returns the correct MudObject# for them.

This works all find and dandy because in echos 1 and 2 it correctly displays the MudID under all conditions, meaning the reference parser is fine. Now my problem was that echos 3 and 4 were blank even though I was simply copying an already existing reference array.

Now previously in the object is another variable, the reference to the archetype which is just a single reference and not an array, this was copied to the current object just fine in all cases. Now when I tried to copy the array of the two items as a whole, it didn't work for some reason and echos 3 and 4 were blank as I said. Now then, what I did was add in the lines that you see commented out and the script worked fine after that.

Is this a bug or something?

contiga 04-07-2007 09:37 PM

PHP Code:

vars file.getDynamicVarNames(); 


Rapidwolve 04-07-2007 09:57 PM

Quote:

Originally Posted by contiga (Post 1297702)
PHP Code:

vars file.getDynamicVarNames(); 


I was going to say that but I didn't think it was what he needed o_o

contiga 04-07-2007 10:00 PM

Quote:

Originally Posted by Rapidwolve (Post 1297712)
I was going to say that but I didn't think it was what he needed o_o

Well I looked further in the script lol,, and I think that was what he was needing when I looked at this part:
PHP Code:

  for (0vars.size(); ++) {
    
//if (file.(@ vars[i]).type() != 3) {
      
this.(@ vars[i]) = file.(@ vars[i]);... blabla 

What he could also do tho is:
PHP Code:

for ( ivars)
  
this.( @ i) = file.( @ i); 

Way shorter and more "clean" looking.

Inverness 04-07-2007 10:31 PM

God damnit
You people need to read what I wrote in the freaking post. The script works fine already. Stop trying to correct stuff thats not broken.
Quote:

Originally Posted by Chompy
And, you can't send objects(/raw info) as params

You damn well can, object's locations don't change only references to them. The script already works like that, god.

Now here is the problem:
PHP Code:

---------
object1.var = {object3object4};
object2.var = object1.var;
//Objects are lost
---------
object1.var = {object3object4};
object2.var = new [object1.var.size()];
object2.var[0] = object1.var[0];
object2.var[1] = object1.var[1];
//Objects are saved 


Rapidwolve 04-07-2007 10:35 PM

Quote:

Originally Posted by Inverness (Post 1297734)
God damnit
You people need to read what I wrote in the freaking post. The script works fine already. Stop trying to correct stuff thats not broken.

You damn well can, object's locations don't change only references to them. The script already works like that, god.

What the hell?

Inverness 04-07-2007 10:39 PM

I edited my example to be more accurate.
Edit:
I never got the for(var: var) thing down.
So if I did for(i: vars) then would i represent vars[index]?

Chandler 04-07-2007 11:04 PM

Make sure you're getting the var names
PHP Code:

 echo("Vars Found:" SPC getstringkeys("this.mud")); 

I was also thinking about the DynamicVars function.


Also, why do people use files for their mudlibs!
DON'T DO IT, IT ISN'T NECESSARY. :[

Rapidwolve 04-07-2007 11:06 PM

Quote:

Originally Posted by Inverness (Post 1297741)
I edited my example to be more accurate.
Edit:
I never got the for(var: var) thing down.
So if I did for(i: vars) then would i represent vars[index]?

Yes

for (i: vars)
newobj = i;

is equivilant to

for (i = 0; i < vars; i++)
newobj = vars[i];

Inverness 04-07-2007 11:08 PM

Quote:

Originally Posted by Rapidwolve (Post 1297762)
<text>

Ah thanks, no wonder it never worked for me. I don't think that was clearly explained when GS2 was introduced, or maybe I just live under a rock :D

Rapidwolve 04-07-2007 11:59 PM

Quote:

Originally Posted by Chandler (Post 1297761)
Make sure you're getting the var names
PHP Code:

 echo("Vars Found:" SPC getstringkeys("this.mud")); 

I was also thinking about the DynamicVars function.


Also, why do people use files for their mudlibs!
DON'T DO IT, IT ISN'T NECESSARY. :[

It's like an assurance that if something happens the text file will still be there. Say some idiot resets your ItemLib npc, what do you do then o_o

Inverness 04-08-2007 12:01 AM

If you type the items in the script and then compile the script, even if flags are reset you can just recompile the script.

Inverness 04-08-2007 12:05 AM

Quote:

Originally Posted by Chandler (Post 1297761)
Make sure you're getting the var names
PHP Code:

 echo("Vars Found:" SPC getstringkeys("this.mud")); 

I was also thinking about the DynamicVars function.


Also, why do people use files for their mudlibs!
DON'T DO IT, IT ISN'T NECESSARY. :[

What the hell? ARE YOU EVEN READING WHAT I POSTED

And I use files because objects will be SAVED TO FILE when they're not in use. Like when you logoff. My system is designed as an object-controller, current types are (arch, ench, char, plyr, item, cont) for Archetype, Enchantment, (npc) Character, Player, Item, and Container. The files must be saved when they're not in use.

script from mudobject Class
PHP Code:

public function destroyObject() {
  
triggerAll("onDestroyObject"null);
  echo(
"Destroyed MudObject: " this.mudid);
  
MudControl.allobjects.delete(MudControl.allobjects.index(this));
  
destroy();


script from mudint_saveable Class
PHP Code:

public function saveObject() {
  
temp.file 0;
  
temp.vars 0;
  
temp.0;
  
  
file = new TStaticVar();
  
vars this.getMudVars(truetrue);
  
//echo("SaveVars: " @ vars);
  
for (0vars.size(); ++) {
    
file.(@ vars[i]) = this.(@ vars[i]);
  }
  
MudControl.saveRefs(filethis);
  
file.savevars(format("%s/%s/%s.txt"MudControl.mudpaththis.mudtypethis.mudid), 0);
  
  
triggerAll("onSavedObject"null);
  echo(
"Saved Object: " this.mudid);
  
file.destroy();
}
public function 
onDestroyObject_mudint_saveable() {
  
saveObject();


Notice how when an object is (properly) destroyed, it is automatically saved if the object has the Saveable interface.

Chandler 04-08-2007 07:44 AM

Quote:

Originally Posted by Rapidwolve (Post 1297783)
It's like an assurance that if something happens the text file will still be there. Say some idiot resets your ItemLib npc, what do you do then o_o

Don't give that idiot the rights to do such a thing? lol

Also, you can easily program the database to store the items, example.
HTML Code:

function onCreated()
  {
  for (temp.currentItem: getstringkeys("this.item"))
    unset("this.item"@ temp.currentItem);
  this.item1 = {"bomb", "wbomb.png", "weapon", {weight, volume}, {necessary data, such as damage and radius}};
  }

That's how I'd do an item system, instead of storing all of this information. It seems rather pointless if you ask me.

Inverness 04-08-2007 08:09 AM

I don't think you're grasping the fact that my Mud System is for controlling all objects not just items. An item is just one type of object, there are players, npc, and types for the dialog objects, and various other things like organizations.

Kristi 04-08-2007 10:14 AM

Quote:

Originally Posted by Inverness (Post 1297734)
Now here is the problem:
PHP Code:

---------
object1.var = {object3object4};
object2.var = object1.var;
//Objects are lost
---------
object1.var = {object3object4};
object2.var = new [object1.var.size()];
object2.var[0] = object1.var[0];
object2.var[1] = object1.var[1];
//Objects are saved 


Not true, object2.var = object1.var when object1.var is an array works just fine. It does not get lost. You are making a generalized nonexistant error from your specific problem. Your code faulters somewhere else, not on an array=array assignment.

Your problem is you are treating variables like objects. none of these objects are objects, they are just variable. someobj isnt an object, and someobj.something is just a different var, unless you say someobj = someotherobj, or someobj = new TStaticVar(); thus giving it an object definition.

The reason your properties arent copying over from file.whatever to this.whatever is because the whatevers are NOT objects.

in the above example, if object3 and object4 were specifically declared as objects, object1.var would definately reference objects, then object2.var would definately copy over object one, and it would work. the reason it doesnt work is beacuse object3 and object4 arent actually objects yet, and object3.whatever name is just the name of a variable, not a subvariable of the object.

PHP Code:

objj3.lame "hi";
objj4.lame "ho";
objj1.var = {objj3,objj4};
objj2.var = objj1.var;
echo(
objj1.var[0].lame SPC objj2.var[0].lame);
// This echo outputs nothing

objj3 = new TStaticVar();
objj4 = new TStaticVar();
objj3.lame "hi";
objj4.lame "ho";
objj1.var = {objj3,objj4};
objj2.var = objj1.var;
echo(
objj1.var[0].lame SPC objj2.var[0].lame);
// this echo outputs "hi hi" because we actually made objj3 and objj4 objects 


Twinny 04-08-2007 01:16 PM

Quote:

Originally Posted by Inverness (Post 1297695)
READ MY POST BEFORE YOU MAKE YOURSELF LOOK STUPID

You need a chill pill.

Inverness 04-08-2007 09:09 PM

All I want from you people is to tell me why my script doesn't work with those lines commented out, and why it does work correctly when they're not.
Quote:

Originally Posted by Kristi (Post 1297956)
Stuff

Everything you said was completely wrong. You obviously did not read my post either. I see that I'm not going to get any help on these forums so I'll just notify Stefan of the problem and ask him to check it.

You don't seem to understand the fact that in my script shown in the first post. That the script works fine when the commented-out lines are un-commented.
Quote:

Originally Posted by Twinny (Post 1297975)
You need a chill pill.

Considering that Hell Raven didn't read it either, I'd say that is justified.

Kristi 04-09-2007 04:06 PM

Quote:

Originally Posted by Inverness (Post 1298146)
All I want from you people is to tell me why my script doesn't work with those lines commented out, and why it does work correctly when they're not.

Everything you said was completely wrong. You obviously did not read my post either. I see that I'm not going to get any help on these forums so I'll just notify Stefan of the problem and ask him to check it.

You don't seem to understand the fact that in my script shown in the first post. That the script works fine when the commented-out lines are un-commented.

Considering that Hell Raven didn't read it either, I'd say that is justified.

No, he is right. You do need to chill. Apparently you did not read my post either. You said in that one post copying objects did not work like that. It DOES work like that, so you must have never declared them as objects. I was merely correcting false information you gave to the public.

You are loading the vars from a file. therefore, file is an object, but everything else sub of it is a variable. You do not have to believe me though, just see, for example, what file.muditems[0].type() returns, my bet is that it will not return 2 (an object).

Just like my last post stated, that you need to declare an object, or else it is just a variable. How about actually reading my post instead of just accusing me of not reading yours (sheer hypocracy if you ask me).

Quote:

Originally Posted by Inverness (Post 1298146)
Everything you said was completely wrong.

That is ironic when what I said works and what you are doing does not work, hense the reason you posted in the first place.

Inverness 04-09-2007 11:52 PM

Quote:

Originally Posted by Kristi (Post 1298424)
You are loading the vars from a file. therefore, file is an object, but everything else sub of it is a variable. You do not have to believe me though, just see, for example, what file.muditems[0].type() returns, my bet is that it will not return 2 (an object).

The function MudControl.loadRefs(file); converts all object reference strings in the file into the actual MUD object. You still don't seem to understand the fact that the script works EXACTLY RIGHT when the commented-out lines are added in.

Quote:

Originally Posted by Kristi (Post 1298424)
That is ironic when what I said works and what you are doing does not work, hense the reason you posted in the first place.

I didn't post the script because it didn't work. I posted the script because the first way that should have worked didn't work, so I used an alternative. Now if you're done trying to fix my script. Please answer my question, Why does the script work when the commented-out lines are added in. I do NOT need anything else from you but that answer.

If you had clearly read my first post you would understand this.

Edit: Its strange that the object array failed to copy while the object in a different non-array variable copied without a hitch.

Kristi 04-10-2007 04:33 AM

It works because you are using the new command when uncommented. Instead of arguing, see what type that variable is, like I asked before.

Inverness 04-10-2007 05:15 AM

Variable type is 2, an object, live I've been saying.

And for the new command, new [size] constructs an empty array not an object.
It is no different than using setArray(name, size);

Kristi 04-10-2007 09:14 PM

Quote:

Originally Posted by Inverness (Post 1298658)
Variable type is 2, an object, live I've been saying.

And for the new command, new [size] constructs an empty array not an object.
It is no different than using setArray(name, size);

when you use new, it constructs an array capable of holding objects, something that does not happen when you do not use new. Declare this.whatever a TStaticVar, as i said. You are arguing everything without trying it.

Inverness 04-10-2007 10:28 PM

Since when did you need to construct a blank array before copying one?

I already told you that my script works fine when I add in those comments. You've done nothing but try to find some error in my scripting while not even considering that there could possibly be some obscure bug in the engine. I'm irritated by the fact that you've so highly underestimated my ability to script by making me waste my time by checking if the variable is an object when I know damn well that it is.

The only difference between the two scripts is that the working one makes a blank array before copying each variable (object ref in this case) to the new array. There should not be a difference in copying an array of objects as a whole and copying the individual objects into the blank array.

You have yet to explain to me how this simple change that I'm displaying can affect the outcome of the script and until you do so I'm simply not going to bother seeking assistance since it seems that you are not capable enough.

Skyld 04-11-2007 11:04 AM

Quote:

Originally Posted by Inverness (Post 1297734)
Now here is the problem:
PHP Code:

---------
object1.var = {object3object4};
object2.var = object1.var;
//Objects are lost
---------
object1.var = {object3object4};
object2.var = new [object1.var.size()];
object2.var[0] = object1.var[0];
object2.var[1] = object1.var[1];
//Objects are saved 


Please drop the attitude, we are trying to help.

I'm not sure if I've misunderstood where the problem is, but I cannot seem to reproduce this, since the example below is working fine. Is this where your error is occuring?
PHP Code:

function onCreated()
{
  
temp.obj1 = new TStaticVar();
  
temp.obj2 = new TStaticVar();
  
temp.obj3 = new TStaticVar();
  
temp.obj4 = new TStaticVar();

  
temp.obj3.var = "YOU HAVE FAILED TO WATER YOUR CHIA PET";

  
temp.obj1.foo = {temp.obj3temp.obj4};
  
temp.obj2.foo temp.obj1.foo;

  echo(
temp.obj1.foo[0].type()); // producing 2
  
echo(temp.obj2.foo[0].type()); // producing 2

  
echo(temp.obj2.foo[0].var); // producing "YOU HAVE FAILED TO WATER YOUR CHIA PET"


It might be good if you can post some real data from your system that is not copying across properly; if it's a bug then it would be easier to find out how it's happening.

Inverness 04-11-2007 10:30 PM

I apologize for the attitude but it frustrates me when people do not read my explanation of the problem and they attempt to find their own problems without fully understanding what is going on.

I've attempted to reproduce this outside the system myself but was unsuccessful. Though my system has a much more complicated handling of objects so I can't really duplicate everything that is affecting the problem.

The data that I tested before and after the copy was the mudid. Its displayed in the echos numbered 1 to 4. Copying the whole array at once will result in the first two echos displaying the correct IDs before the copy and the second two echos being blank. Adding in the comments results in both sets of echos displaying the correct information.

Edit: The scripts are set up on Symphonia Dev for anyone who wants a crack at it, that has global RC of course.

Inverness 05-30-2007 01:31 AM

So can this be looked into at all? -_-

xAndrewx 05-30-2007 08:12 AM

HTML Code:

  //Loading all the possible var names...
  vars = file.getVarNames();
  //However, you're only wanting to remove this
  vars.remove("mudid");
  //Shouldn't it be
  vars.remove(this.muditems[0].mudid);

Looking more into it

HTML Code:

  //You're removing vars, then you're trying to assign a new var...
  vars.remove("mudid");
  vars.remove("mudtype");
  for (i = 0; i < vars.size(); i ++) {
    this.(@ vars[i]) = file.(@ vars[i]);
  }

Use this loop

HTML Code:

  for (temp.currentVar: vars) {
    this.(@ temp.currentVar) = makevar(file.( @ temp.currentVar));
  }

If all else fails, make sure your way of setting the ''new vars'' actually works, try echoing the vars after you've added them. [Don't do the file. stuff, make it all one string being "hello"]

HTML Code:

  for (temp.currentVar: vars) {
    this.(@ temp.currentVar) = randomstring("hello", "hi", "yo");
  }
  echo(this.getVarNames());


Inverness 05-30-2007 09:13 AM

Is everyone on this forum incapable of actually reading my post.

Note 1: My script works PERFECTLY when the commented-out lines are edited in.
Note 2; I stated this several times.

I only want ONE question answered. Why do the commented-out lines make the difference in which this script works and doesn't work?

Quote:

Originally Posted by xAndrewx (Post 1313317)
HTML Code:

  //Loading all the possible var names...
  vars = file.getVarNames();
  //However, you're only wanting to remove this
  vars.remove("mudid");
  //Shouldn't it be
  vars.remove(this.muditems[0].mudid);


No, vars is a list of the names of the variables that will be copied, mudid is the name of a variable I don't want copied. Stop trying to fix whats not broken and READ MY POST.
Quote:

Originally Posted by xAndrewx (Post 1313317)
HTML Code:

  //You're removing vars, then you're trying to assign a new var...
  vars.remove("mudid");
  vars.remove("mudtype");
  for (i = 0; i < vars.size(); i ++) {
    this.(@ vars[i]) = file.(@ vars[i]);
  }


I'm removing the NAMES of vars that would break the mud object considering these are 'read-only' vars and should never be changed. If their name is not in the list, they will not be copied. mudid and mudtype are both assigned by the newObject() function in the MudControl. Once again, this is NOT the problem, READ MY POST.
Quote:

Originally Posted by xAndrewx (Post 1313317)
HTML Code:

  for (temp.currentVar: vars) {
    this.(@ temp.currentVar) = makevar(file.( @ temp.currentVar));
  }

If all else fails, make sure your way of setting the ''new vars'' actually works, try echoing the vars after you've added them. [Don't do the file. stuff, make it all one string being "hello"]

HTML Code:

  for (temp.currentVar: vars) {
    this.(@ temp.currentVar) = randomstring("hello", "hi", "yo");
  }
  echo(this.getVarNames());


Why are you trying to fix something that isn't broken?

Kristi 06-01-2007 04:45 PM

Quote:

Originally Posted by Skyld (Post 1299065)
It might be good if you can post some real data from your system that is not copying across properly; if it's a bug then it would be easier to find out how it's happening.

Which you still have failed to do. Show us the data that fails ^_^

Inverness 06-01-2007 08:51 PM

Quote:

Originally Posted by Kristi (Post 1314102)
Which you still have failed to do. Show us the data that fails ^_^

Do you forget things so easily?
I told you the files were on Symphonia Dev and I gave you RC and NC rights and you even logged on there to look at them yet you never actually did anything or even looked at them. I'm not going to set them up again just for you after I already did.

The files are available for download in this thread, the system I'm talking about would be the second one in the file.

I haven't "failed" to do anything.

Inverness 07-17-2007 10:02 AM

Bump.

Inverness 08-12-2007 08:57 PM

Bump.

I'm waiting for someone to apologize for being an arrogant jerk.


All times are GMT +2. The time now is 12:18 PM.

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