MODULE: Properties v3.12 - Updated 06 October 2008

Started by monkey0506, Tue 11/07/2006 06:14:30

Previous topic - Next topic

monkey0506

The Properties module provides methods for the user to create, edit, and delete custom properties via the script at run-time.

06 October 2008

Okay, I'm fairly certain this is the last major bug fix. Originally the point of eProperties_MaxRooms was to prevent the property functions being used in rooms numbered higher than that, but I forgot one line of code (in 12 places!) and it would crash the game if you didn't manually specify a room while the player was in an unsupported room.

I've also implemented default interaction methods. In the included documentation they're listed at the very bottom with a special note that they are only included pending the definition of the PROPERTIES_DEFAULTINTERACTION macro (which is defined by default). This defines the property DefaultInteraction to simplify the process for games which would like the ability to define default interactions (for example, the default for the property is eModeWalkto but for oDoor you may want to change the default interaction to eModeOpen (SCUMM interfaces) or eModeInteract).

05 October 2008

No point bumping this thread again, I'll just put the update here and be on my way. I realized in using the module that I'd mucked up the inventory functions which have now been fixed. Unlike Characters, InventoryItems are indexed from one not zero. All the room-based functions are handled differently anyway and are unaffected. But it's been fixed as of v3.11.

30 September 2008

This isn't a major update over v3.0, but there are some important changes. The module now defines static limits on the number of properties. These can be changed, but if you're going to change them you should read the included documentation/commentation first.

Also, you can once again delete properties. Instead of "removing" the entry, I simply reuse the slot and keep track of the lowest available slot number.

Aside from that this release is largely the same as 3.0. If you have any questions, comments, or otherwise, feel free to post or PM me. -monkey

[Module Pros:]

  • Create custom properties at run-time.
  • Delete custom properties at run-time.
  • Edit custom properties at run-time.

[Module Cons:]

  • All properties must be created, deleted, and set from within the script. You can't use the built-in Properties Schema Editor.
  • There is currently no "friendly" description of the properties. If requested this may change. Actually since the "name" of the property is a String, you can make the name as friendly as you'd like.


Download here (Requires AGS v3.1.0 or higher)
View the manual online
v3.0 Mirror 1
v3.0 Mirror 2 Thanks again Neole!
Download v2.0 (for use with AGS 2.72)
Mirror v2.0 Thanks Neole!
Mirror v1.0 Thanks jasonjkay!

For more information on what custom properties are, RTFM n00b! :=

jasonjkay

Sounds great, ill add it to my site.
http://www.americangirlscouts.org/agsresources/ - Mods, plugins and templates.

SSH

It would be great if there was a way for this module to scan through the Properties from the schema editor at game and room load and automatically copy these in...
12

monkey0506

AFAIK there isn't a way to do that...is there???

If there is that would be great. But...I don't seem to see any type of function to check if a property with a certain name exists or what said property would already be applied to if it did exist...?

If you know something I don't...please tell. Unless of course you're just saying it would be nice to not have to manually transfer all your existing properties. :P

SSH

In the meantime, you could have a function that took a comma-separated String that was a list of properties to load from the schema...
12

Kweepa

Or save yourself the parsing trouble and just call the function once for each property.
Still waiting for Purity of the Surf II

monkey0506

*bump for update!*

I've included the changelog for version 2.0 in the first post, and I mentioned that this was a major rewrite of the module. What I forgot to mention there though was that v2.0 saves memory as well! You'll save 360 KB on your compiled EXE's size just by replacing v1.0 with v2.0, and an additional 4 KB per property. Unfortunately* all the functions for setting the properties have been revised, so you'll have to rescript all those parts. However I never actually got word anyone was actually using this...so hopefully it won't cause too many problems. ;)

~Cheers guys!

*It's only unfortunate if you were actually using the module. The new function list is much more reasonable and much more manageable as well.

monkey0506

Well folks I've done it again. I've completely changed just about every function this module implemented. 8)

But I did it with good reason. With AGS 3.0 right around the corner I knew I'd better sneak this in there pretty quick. Now using dynamic arrays and extender methods, this is looking better than ever. I realize at this point that I've never provided any example code of how this works, and any new users who might be interested in the script would probably benefit from this.

The first thing we'll need to do is create some properties. One common example might be implementing a "Health" property for your Characters. So to create the "Health" property we would do this:

Code: ags
// inside of game_start in your global script
Properties.CreateProperty("Health", 100); // create a new number property called 'Health' with a default value of 100


That's simple and straightforward enough. Next we'll need to see how our properties are used. Say our player drinks a potion:

Code: ags
// interaction for player drinks potion
player.SetCustomProperty("Health", player.GetCustomProperty("Health") + 15); // player drank potion, add 15 hp


You can also use text properties, just look up the function in the provided manual.

Rui 'Trovatore' Pires

Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

monkey0506

Damn it. They finally got around to upgrading my server. Which means they'll be formatting it now. Blasted free hosting. I'll upload it to some of my other free accounts. := And possibly try to remember the links for those AGS-based hosting solutions...

monkey0506

Dear Warning,

  Thank you for your concern. However, I am sure that I wish to reply to this thread to promote awareness that a new version of my module has been uploaded.

Thank you,

monkey_05_06


(aka, BUMP FOR UPDATE!)

The module's back up, with a fix. v3.0 had a slight bug in it if you wanted more than...I believe just a few properties. So for anyone wishing to use this module (including myself, yay!), it's now available once more for download (of course it has been via the mirrors, but I'd been meaning to release a bug-fix anyway). ;)

incobalt

I'm really looking forward to using this.  I did want to say that while you mention that the module requires 3.02 AGS or higher, it looks like it's actually using the 3.0.1 beta.  I had to change IndexOf to Contains in order to use it on my non-beta AGS (the beta changed it to IndexOf back in beta 1, apparently: "* Renamed String.Contains to String.IndexOf to reduce confusion with other languages such as Java and C#. String.Contains will continue to work as well for the foreseeable future").  Just thought you might like to know and others might if they also get this problem when trying to compile their games.

monkey0506

Sorry about the confusion there. For the record, you are right. I simply forgot that I was using that. I didn't think I was using any of the new features introduced by the BETA but I completely overlooked that one. Thanks for the report!

Also, it's not clearly documented but just because it was something I encountered today, eProperties_MaxRooms should always be higher than the actual number of rooms in the game. I would normally decrease the room index by 1 like I did for InventoryItems, except it is possible to be in room 0 (at least AFAIK, intro.crm would return 0 from player.Room).

Crimson Wizard

#13
I have a suggestion to follow latest changes in AGS and make properties be applied to different types of game elements if only explicitly told to; in other words there should be separate properties for Rooms, separate for Objects, etc.

By the way, a little offtop, perhaps, but aren't there any plans to allow intrinsic AGS properties be changed during runtime?

monkey0506

I'm sorry but I don't understand exactly what you mean..are you referring to the idea that properties should be applied separately for different types (each with their own list of properties) as opposed to the current implementation where there is one list of properties that can have values set by the actual items using them?

If so, I have no intention of adding that functionality to my module any time in the near future.

As for allowing custom properties (the built-in, user defined properties) to be edited at run-time that has been discussed several times, but I've never seen CJ make any remark to the effect that it was something he considered high priority. So, I wouldn't be holding my breath on that personally.

Worse_Username

Hello, I'm having some trouble with the module. There were no apparent problems when importing it, the autocomplete feature immediately started suggesting functions from the module. But I can't get the Properties::Create function to work. I've tried it multiple times in different ways to no avail.
Eventually I've managed to conclude, that the function simply doesn't work. For example, I assigned this code to an object interaction:
Code: AGS
Properties.Create("p", 100);
Display ("Does p exist:%d", Properties.Exists("p"));

It displays "Does p exist:0". This left me completely dumbfounded. Why would something so simple not work? There doesn't seem to be anything similar to my problem in this thread.

I've tried the above code without creating any other custom properties through script or even AGS GUI. I'm using the latest versions for both this module (v3.12) and AGS (3.2.1). I'm running it on Windows XP.

Is this a bug or am I still missing something? Thanks.


Ghost

Quote from: Worse_Username on Thu 04/07/2013 17:53:02
Is this a bug or am I still missing something? Thanks.

The %d token displays an integer, but "p" is a string. Try %s instead to see if the proper value is returned.


Kitai

Quote from: Ghost on Fri 05/07/2013 00:09:14
The %d token displays an integer, but "p" is a string. Try %s instead to see if the proper value is returned.
No, it's not the problem: the Exists method of this module gives you a bool. In AGS you can display the value of a bool in a string by supplying it as a %d.
But Worse_Username, you can directly check for the value that Create returns, which is -1 if the property was not created.

Worse_Username

Managed to solve the issue. Apparently, MaxProperties being set to 1 by default was causing it. After setting it to a higher value everything started working.

monkey0506

..why would MaxProperties have been set to 1 by default? What was I thinking?? Glad you got it sorted. ;)

SMF spam blocked by CleanTalk