Please login or register.

Login with username, password and session length
Advanced search  

News:

Latest WME version: WME 1.9.1 (January 1st, 2010) - download

Author Topic: Accessing "self.array" in Custom Objects  (Read 6593 times)

0 Members and 1 Guest are viewing this topic.

creatorbri

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Posts: 61
  • I'm a llama!
    • View Profile
Accessing "self.array" in Custom Objects
« on: December 09, 2003, 11:20:00 PM »

I'm trying to access an array inside an object by doing something like this:

Code: [Select]
var tempList = self.ListArray;
// do something with tempList[0]

But the engine hangs. If I comment the first line, it compiles. As far as I can tell this only seems to happen when using self.whatever inside a custom object script, and only when 'whatever' is an array. Regular variables work fine. Is it the same problem as the nested objects, or something different?
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re:Accessing "self.array" in Custom Objects
« Reply #1 on: December 10, 2003, 12:06:32 AM »

Could you be more specific about the details, please?

I tried this:
Code: [Select]
// create an array
var TestArray;
TestArray[0] = "aaa";   
   
// store in an attribute
this.TestArray = TestArray;
      
// read it back
var Something = this.TestArray;
Game.Msg(Something[0]);


and this:

Code: [Select]
// create an array
var TestArray = new Array();
TestArray[0] = "aaa";   
   
// store in an attribute
this.TestArray = TestArray;
      
// read it back
var Something = this.TestArray;
Game.Msg(Something[0]);

and both seem to work.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

creatorbri

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Posts: 61
  • I'm a llama!
    • View Profile
Re:Accessing "self.array" in Custom Objects
« Reply #2 on: December 10, 2003, 02:03:20 AM »

Well, that's about it, except that the lines of code were inside of a custom object script, attached as follows:

Code: [Select]
var TempObject = new Object ("comment_object.script");and the code in question is inside comment_object.script:

Code: [Select]
var tempList = self.ListArray;
// do something with tempList[0]

method Add (parameters)
{
     var List = self.ListArray;
}

I noticed that you use 'this' instead of 'self' -- I've been using 'self' because in most cases it seems to be working. Is 'self' a synonym of 'this', or is this just my crazy good luck running out?

Perhaps I'll try using 'this' later tonight and see if it makes a difference..
Logged

creatorbri

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Posts: 61
  • I'm a llama!
    • View Profile
Re:Accessing "self.array" in Custom Objects
« Reply #3 on: December 10, 2003, 06:27:45 AM »

I made a couple changes, and after replacing 'self' with 'this' seemed to work, and I thought it was just because I was being stupid (which I'm sure I was, but that's not the point). Then I added this new bit of test code:

Code: [Select]
var List;
List[0] = null;

var tempList;
tempList = this.List;
And it broke again.

Looking closer, this is what I believe your test code is essentially doing, in the context of my example:

Code: [Select]
var tempList;
tempList[0] = null;  
   
// store in an attribute
this.List = tempList;
Which seems to be the exact opposite of what I'm trying to do. Unless I'm not thinking clearly, which is entirely possible, because I'm very tired.
Logged

creatorbri

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Posts: 61
  • I'm a llama!
    • View Profile
Re:Accessing "self.array" in Custom Objects
« Reply #4 on: December 13, 2003, 10:12:56 PM »

I still haven't been able to solve this problem. :( Any more ideas?
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re:Accessing "self.array" in Custom Objects
« Reply #5 on: December 15, 2003, 10:50:51 AM »

I still don't know if I understand you correctly, but here are a few notes:

var List; is not equal to this.List

The first one is a local variable while the second is an attribute. You don't have to declare attributes.

And, yes, this is a synonym for self, I renamed it some time ago to be more consistent with other languages.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

creatorbri

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Posts: 61
  • I'm a llama!
    • View Profile
Re:Accessing "self.array" in Custom Objects
« Reply #6 on: December 16, 2003, 05:00:21 PM »

I understand that "this.List" is not the same as "var List" -- honestly I'm not quite sure why I typed my last example like that  ::). Guess that doesn't help me get closer to an answer.

I'm just gonna send you my project, minus large resource files, and maybe you can let me know if it crashes for you also.
Logged

Jerrot

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 690
    • View Profile
Re:Accessing "self.array" in Custom Objects
« Reply #7 on: December 16, 2003, 05:49:02 PM »

I'm just gonna send you my project, minus large resource files, and maybe you can let me know if it crashes for you also.

If you like, feel free to send it to me, too.
Logged
Mooh!
 

Page created in 0.04 seconds with 24 queries.