Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ SMAUG ➜ SMAUG coding ➜ accessing members of a structure

accessing members of a structure

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Gohan_TheDragonball   USA  (183 posts)  Bio
Date Thu 06 Dec 2007 12:20 PM (UTC)
Message
i was wondering if something like this is possible (pseudo code for example)


    char arg[MAX_STRING_LENGTH];

    argument = one_argument(argument, arg);

    if ( is_struct_member(ch,arg) )
    {
	ch->(arg) = argument;
    }
    else
    {
	prog_bug( "Accessing invalid member of character structure.", mob );
    }


what i am trying to find out is if i can code in a way to directly manipulate/access members of any given structure, whether it be character/mobile/object/room, based on a given string. any ideas or suggestions or links would be very appreciated.
Top

Posted by ThomasWatts   USA  (66 posts)  Bio
Date Reply #1 on Thu 06 Dec 2007 02:51 PM (UTC)
Message
What you want to do is not possible in C that I know of. What you want instead is a lookup table.
Top

Posted by Gohan_TheDragonball   USA  (183 posts)  Bio
Date Reply #2 on Thu 06 Dec 2007 03:19 PM (UTC)
Message
well i already know of what i will do if this is not possible, but that requires programming in every variable possiblity for each structure, and would have to update in future variables as they were added, i was hoping for a more dynamic structure.
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #3 on Thu 06 Dec 2007 08:56 PM (UTC)
Message
There is simply no way to access the members of a structure at runtime without adding code to do it yourself. C simply does not provide that kind of mechanism. And yes, if you do it with a straightforward table, you will need to update it every time you add a fixed field.

If this is an important thing for you, you should consider making your entire structure dynamic, as Thomas suggested. Instead of having a struct with fixed fields, you can have a struct with a single lookup table mapping field name to field value. Of course, this is a whole lot easier in C++ than in C ... and it's worth mentioning that it's also a whole lot easier in Lua than in C++.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

Posted by Gohan_TheDragonball   USA  (183 posts)  Bio
Date Reply #4 on Fri 07 Dec 2007 01:19 PM (UTC)
Message
its fine i will just do it the way i am doing it right now, just more to type. its not that important, just would have been cool to implement, both for the script system but also just for the xp of doing it. as for lua, that is a nice scripting system, but what is the point of it, i never checked it out in depth, how does a builder modify a script in-game?
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #5 on Fri 07 Dec 2007 03:58 PM (UTC)
Message
In this case you wouldn't be using Lua just to do builder scripts anymore, you would be using Lua to implement parts of the game itself. For an example, see Nick's quest system in Lua; note that player questing data is stored in Lua data structures, not C.

Still, if you were using Lua for mudprogs, editing them would work the same way as current editing does. Just pull up the text into a buffer and edit it. :-)

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


17,667 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.