realbasic-games
[Top] [All Lists]

Re: Dynamic Property Access

To: REALbasic Games <realbasic-games at lists dot realsoftware dot com>
Subject: Re: Dynamic Property Access
From: "Joseph J. Strout" <joe at realsoftware dot com>
Date: Wed, 21 Sep 2005 08:11:44 -0600
Delivered-to: realbasic-games at lists dot realsoftware dot com
References: <F92AA7B9-2E7A-483F-A17F-3717EC5E2130 at lenwhite dot com>
At 11:37 PM -0700 9/20/05, Leonard White wrote:

That is, I want to evaluate "prop_" + variable, where variable = "stamina" and the property I'm trying to set is called "prop_stamina", say. So the property name is first constructed then I can access the resulting string AS as property name.

There are a couple ways to do this, some of which (Operator_Lookup) give up compile-time checking of your code (like scripting lanugages), so I wouldn't recommend that.

Instead, when I need this, I just add GetProp and SetProp methods, each of which has a Select Case that sets/gets the appropriate property based on the given property name. Yes, this means you have to update these two functions whenever you change the set of properties, but in the context of all the work needed to write a game, this is trivial.

Best,
- Joe

--
Joe Strout                          REAL Software, Inc.

Vote for REALbasic (twice!) in the LinuxWorld Reader's Choice Awards:
http://linux.sys-con.com/general/readerschoice.htm
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

<Prev in Thread] Current Thread [Next in Thread>