ObjectListSort not working ?

Thierry
29 Sept 2013, 14:40
Hello guys ! I'd like to sort an object list alphabetically, so I've tried to use this function. Here is an example I wrote with 2 objects :

create ("Beta")
create ("Alpha")
Test = NewObjectList()
list add (Test, Beta)
list add (Test, Alpha)
sortedlist = ObjectListSort (Test, "name")
DisplayList (Test, true)

But the list keeps displaying as follow :

Object: Beta
Object: Alpha

Did I miss something ? And besides, is there any way to display only objects names, without the "object:" thing before ?

Thank you very much for your help :wink:

jaynabonne
29 Sept 2013, 17:48
What happens if you display "sortedlist" instead? (The sorted one, not the original.)

jaynabonne
29 Sept 2013, 17:54
To display names from a list, you can just loop through them:

foreach (entry, list) {
msg(entry.name)
}

Thierry
29 Sept 2013, 18:09
Wow, thanks a lot jaynabonne ! You were twice right : by changing "test" in "sortedlist" in the Displaylist line, the alphabetical order is OK.
And by replacing this Displaylist line with your code (and keeping "sortedlist" as source, of course), the "object:" thing is removed. Exactly what I wished :D

Thank you very much, really. You helped me several times, and I learnt a lot of things thanks to you :wink:

Thierry
29 Sept 2013, 21:05
Damn, got another problem... Let's say I used my previous scripts (creating an object list and put two items Inside) in a room A, and then I go into a room B where there is another object I want to create and then add to my list. I tried something like this :

create ("Gamma")
list add (Test, Gamma)

But I got this message : "Error running script: Error compiling expression 'Test': Unknown object or variable 'Test'". It seems as if the list I created in room A wasn't "moved" into the room B... So I tried to put the "new object list" variable as a start script or as a child of the "player" object, but the result was the same. Does a list only work in the room where it has been created ?

jaynabonne
29 Sept 2013, 21:29
Variables that are not attached to objects are just local variables to the *script*. They disappear once the script is done.

Try using game.Test (or player.Test) instead of just Test, and it will persist.

Thierry
29 Sept 2013, 21:48
Once again, thank you jaynabonne ! It works perfectly now :wink:

HegemonKhan
29 Sept 2013, 22:19
a useful thing you can do for organization is this:

instead of cluttering up your "game" and~or Player Objects (such as the default "player" Player Object), you can create a "data object":

<object name="global_data_object">
<inherit type="editor_object" />
<parent>null</parent>
</object>


and then instead of doing:

list add (game.test, "Alpha")
or
list add (player.test, "Alpha")

you can do this:

list add (global_data_object.test, "Alpha")
list add (global_data_object.test, "Beta")
list add (global_data_object.test, "Gamma")

which would then look like this in code:

<object name="global_data_object">
<inherit type="editor_object" />
<parent>null</parent>
<test type="objectlist">Alpha;Beta;Gamma</test>
</object>


instead of cluttering up your "game" or "player" Objects:

(your "game" Object and Player Objects are already probably cluttered with enough attributes already, especially your Player Objects: strength, endurance, etc etc etc such "Stat" Attributes)

<object name="game">
// blah coding
<test type="objectlist">Alpha;Beta;Gamma</test>
// blah coding
</object>


or

<object name="player">
<inherit name="editor_object" />
<inherit name="editor_player" />
// blah coding
<test type="objectlist">Alpha;Beta;Gamma</test>
// blah coding
</object>


-----------------------------

here's an example of me using a "data object" for my work on time+date coding:

<object name="global_data_object">
<inherit name="editor_object" />
<global_turns type="int">0</global_turns>
<am_or_pm type="string"></am_or_pm>
<hour_string type="string"></hour_string>
<day_string type="string"></day_string>
<month_string type="string"></month_string>
<months_of_the_year type="simplestringlist">january;february;march;april;may;june;july;august;september;october;november;december</months_of_the_year>
<days_of_the_week type="simplestringlist">sunday;monday;tuesday;wednesday;thursday;friday;saturday</days_of_the_week>
<month_conversion type="simplestringdictionary">january=0;0=january;february=1;1=february;march=2;2=march;april=3;3=april;may=4;4=may;june=5;5=june;july=6;6=july;august=7;7=august;september=8;8=september;october=9;9=october;november=10;10=november;december=11;11=december</month_conversion>
<day_conversion type="simplestringdictionary">sunday=0;0=sunday;monday=1;1=monday;tuesday=2;2=tuesday;wednesday=3;3=wednesday;thursday=4;4=thursday;friday=5;5=friday;saturday=6;6=saturday</day_conversion>
<clock_time type="string">global_data_object.hour_integer + ":" + global_data_object.minute_integer + ":" + global_data_object.second_integer</clock_time>
<second_integer type="int">0</second_integer>
<minute_integer type="int">0</minute_integer>
<hour_integer type="int">0</hour_integer>
<date_time type="string">global_data_object.month_integer + 1 + "/" + global_data_object.day_integer + 1 + "/" + global_data_object.year_integer</date_time>
<day_integer type="int">0</day_integer>
<week_integer type="int">0</week_integer>
<month_integer type="int">0</month_integer>
<year_integer type="int">0</year_integer>
</object>


having this huge chunk of attributes on my "game" Object or Player Objects would really clutter them up, which would be really messy and a big hassle. This is why making an Object (a "data object") specifically for holding attributes is so nice, hehe.

you could make multiple "data objects" too:

<object name="boolean_data_object">
<inherit name="editor_object" />
<parent>null</parent>
<dead type="boolean">false</dead>
<undead type="boolean">false</undead>
// etc boolean attributes
</object>

<object name="string_data_object">
<inherit name="editor_object" />
<parent>null</parent>
<race type="string">human</race>
<class type="string">warrior</class>
// etc string attributes
</object>

<object name="integer_data_object">
<inherit name="editor_object" />
<parent>null</parent>
<strength type="int">0</strength>
<endurance type="int">0</endurance>
// etc integer attributes
</object>

<object name="game_objectives_missions_boolean_data_object">
<inherit name="editor_object" />
<parent>null</parent>
<got_dragon_slayer_sword type="boolean">false</got_dragon_slayer_sword>
<drank_fire_immunity_potion type="boolean">false</drank_fire_immunity_potion>
<found_key_to_sky_tower type="boolean">false</found_key_to_sky_tower>
<killed_king_of_dragons type="boolean">false</killed_king_of_dragons>
<rescued_princess type="boolean">false</rescued_princess>
// etc game completion required checklist of boolean attributes
</object>

etc etc etc "data objects"

jaynabonne
29 Sept 2013, 22:38
Just a suggestion: rather than having a global "place to collect all sorts of unrelated data", you might want to consider creating objects that group like things. You seem to have actually done that in your example - all the data is time related, but you still have a generic name like "global_data_object". What I'm getting at is, you might want consider naming it something a bit more specific (e.g. time_manager or something) to force you to keep your global objects specific to certain needs.

I know in my own work, it has helped keep the code sane. When I need a new attribute, I have to actually pick the right place to put it. It will help modularize your code (which you seem to be doing quite well with, by the way; so I thought I'd throw in some more "advanced" ideas. :) )

HegemonKhan
29 Sept 2013, 22:39
lol, I was just editing in that very option in my previous post, laughs.

and, I always got open ears for you code vets' tips and tricks with code organization+structure+standardizations, hehe :D

------

and ya, there's the organization+structure component to game creation:

1. Programming~Coding
2. Game Design
3. Game Mechanics
4. Game Balance
5. Authorship (Writing and~or Orally: Story~Plot and dialogue)
6. Media (graphics, music, voice~dialogue, and etc)

7. Game+Code Organization System~Structure (including the labelization of coding elements)

I'm slowly learning some "tactics", and am slowly building up my own structure~system with coding labelization and etc, hehe.

I'm sure everyone has spotted much of this, hehe. I'm developing my "standardization" of coding, such as with attributes and how I label them, and etc.

Thierry
29 Sept 2013, 23:01
Thanks both of you, your tips are really precious ! I'll try to keep learning and using them :wink:

HegemonKhan
30 Sept 2013, 00:22
here's my library file organization:

(I'd also have many more layer of subcategories too... like splitting up the categories of the various verbs, functions, scripts, commands, and etc)

<library>

<!-- Libraries -->

<!-- Templates -->

<!-- Normal Templates -->

<!-- Dynamic Templates -->

<!-- Verb Templates -->

<!-- Verbs -->

<!-- Commands -->

<!-- Functions -->

<!-- Turn Scripts -->

<!-- Timers -->

<!-- Object Types -->

<!-- Attributes -->

<!-- Strings -->

<!-- Booleans -->

<!-- Integers -->

<!-- Doubles -->

<!-- Lists -->

<!-- String Lists -->

<!-- Object Lists -->

<!-- Dictionaries -->

<!-- String Dictionaries -->

<!-- Object Dictionaries -->

<!-- Script Dictionaries -->

<!-- Scripts -->

<!-- Inherited -->

<!-- Object Attributes -->

<!-- Objects -->

<!-- New Game Code -->

<!-- Game Object -->

<!-- Player Objects -->

<!-- Room Objects -->

<!-- Object Objects -->

<!-- Object and Room Objects -->

<!-- Data Objects -->

<!-- Systems -->

<!-- Combat System -->

<!-- Magic System -->

<!-- Equipment System -->

<!-- Storage System -->

<!-- Stealth System -->

<!-- Diplomacy System -->

<!-- Science~Technology System -->

<!-- Character System -->

<!-- Travel System -->

<!-- Shopping System -->

<!-- My Own Notes -->

</library>


yes, there's some redundency, but the organization speed of finding what you need, makes up for the extra work, hehe.