Digital Workshop

Welcome to the Digital Workshop Message Boards
It is currently December 22nd, 2024, 12:04 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Create user defined object - and read from it
PostPosted: October 25th, 2013, 9:14 pm 
Offline

Joined: June 24th, 2010, 9:22 am
Posts: 19
Opus: Pro 8.5 Version 9 preview
OS: Windows 7 Home premium, Windows Vista Business
System: Quad 6600, 3 gig RAM
Hi there

For a Hidden Object Game I need to keep the history of graphical objects on several pages in the game. For example if a user picks up a coin in a room, then later returns to that room, his saved game should have saved the "state" of the coin in the room, for example:

Code:
room1State = new Object(); //this is the user defined object
room1State.coin1 = false;
room1State.coin2 = true; //coin was picked up


Using the following code I can "inspect" the object I created:

Code:
for (property in object){
    Debug.trace(property + "  "  + object[property] + "\n");
}


The output in the Debug window for the above code is:

Quote:
valueOf [Function built-in]
toString [Function built-in]
constructor [Function constructor]

coin2 true
coin1 false


The above code sort of works, except for the "Function built-in" references? How can I "print" or "view" all the data/properties stored in an object if I don't know how many properties there are, or what their names are?

Thank you

Stefan


For this message stefangas has been thanked by : mackavi


Top
 Profile Visit website  
 
 Post subject: Re: Create user defined object - and read from it
PostPosted: October 27th, 2013, 11:57 am 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
I'm afraid you've answered your own question. You need to use property in object and clean up the output.

@imsmackavi

_________________
When you have explored all avenues of possibilities, what ever remains, how ever improbable, must be the answer.

Interactive Solutions for Business & Education
Learn Anywhere. Learn Anytime.

www.interaktiv.co.uk
+44 (0) 1395 548057


Top
 Profile Visit website  
 
 Post subject: Re: Create user defined object - and read from it
PostPosted: October 29th, 2013, 8:35 pm 
Offline

Joined: June 24th, 2010, 9:22 am
Posts: 19
Opus: Pro 8.5 Version 9 preview
OS: Windows 7 Home premium, Windows Vista Business
System: Quad 6600, 3 gig RAM
Aah. Excellent Mack. Thank you for the confirmation and taking the time to answer.

Just to finish the post.... I checked and found that consistently the first three entries for the object contained the stuff that I did not want, so it seems that the code below (I know it's simplistic) works. It only uses object properties and values from index 3 onwards.

Code:
testObj = new Object();
j = 0;
for (property in object){
   if(j>2) {
      Debug.trace(property + "=" + object[property]);
   }
   j++;         
}


For this message stefangas has been thanked by : mackavi


Top
 Profile Visit website  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Google [Bot] and 37 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group