Top Mud Sites Forum Return to TopMudSites.com
  Top Mud Sites Forum > Mud Development and Administration > MUD Coding
Read-only archive
The Top Mud Sites forum is closed.
Posting, registration and logins are disabled.

 
Old 04-24-2002, 06:05 PM   #1
Sitral
New Member
 
Join Date: Apr 2002
Posts: 11
Sitral is on a distinguished road
Red face

Let me start by saying I'm as green as they get, so bear with me.  I'm also not familiar with this type of forum, so I hope this posts correctly...

This _seems_ simple enough, but I'm running into errors.  The long and short of it is this: I want to take what a character puts in and store it in a structure, along these lines:

[code]
struct form { char * input[MAX_STRING_LENGTH]; };
struct form structure { '\0' };
for( i=0; structire.input[i] != '\0'; i++ ) {}
/* If there's something there, skip it! */
structure.input[i] = argument;
/* After we found a blank spot, store the input. */
[/quote]

I want the user to be able to "store say haha!", "store say You're under my power!", "store say Foolish mortal!", then be able to execute all three says with one command. It stores the first one fine, but when I try to store a second command, it changes the first to what I want the second to be, and adds that second.  When I store a third command, all three become that last command.  The above example would store "say Foolish mortal!" three times.

First thing that came to my mind is that there had to be a problem with my for statement, but a bit of elementary debugging seems to prove it works fine.  I then recalled (and verified) that every instance of an array in my book (a poor one, I'm told) only has single characters.  Can 'structure.input[0] = say hahaha!'?  Can/Must I use a multi-dimentional array to store strings?  That last didn't seem to work for me...

Hope it was clear and concise. Thanks.
 
Old 04-24-2002, 06:53 PM   #2
Yui Unifex
Senior Member
 
Join Date: Apr 2002
Location: Florida
Posts: 323
Yui Unifex is on a distinguished road
Question

Yes you must have a multidimensional array to handle this sort of thing. But I'm guessing that you're not properly handling this array, and that's what's causing your problems. Here's an implementation that should work. A note of warning though, it's untested =)

[code] /* on the character structure */
char **storage;
int storage_size;

/* on character initialization */
character->storage_size = 0;

/* in your storage command */
int i;
char **new_storage;

++character->storage_size;
new_storage = malloc(sizeof(char **) * character->storage_size);

for (i = 0; i < character->storage_size - 1; ++i)
new_storage[i] = character->storage[i];
free(character->storage);

new_storage[character->storage_size - 1] = strdup(new_thing_to_store);
character->storage = new_storage;

/* on character deletion */
int i;
for (i = 0; i < character->storage_size; ++i)
free(character->storage[i]);
free(character->storage);[/quote]

It would be wisest to make those into seperate functions that operate on the storage array and size, but that should give you an idea of how to do it.
 
Old 04-24-2002, 08:15 PM   #3
Sitral
New Member
 
Join Date: Apr 2002
Posts: 11
Sitral is on a distinguished road
Exclamation

 
Old 04-24-2002, 10:56 PM   #4
Koryon
Member
 
Join Date: Apr 2002
Location: Canada
Posts: 50
Koryon is on a distinguished road
 
Old 04-25-2002, 06:23 AM   #5
Yui Unifex
Senior Member
 
Join Date: Apr 2002
Location: Florida
Posts: 323
Yui Unifex is on a distinguished road
Question

No he doesn't =P. str_dup() is a Diku function. strdup() is a BSD function, and I free it with free().
 
Old 04-25-2002, 06:30 AM   #6
Seth
Senior Member
 
Join Date: Apr 2002
Location: Ede, The Netherlands
Posts: 271
Seth is on a distinguished road
On the other hand, you could tell players to get a decent client with scripting functions, then give them a good VB/J/Javascript site with tutorials.
 
Old 04-25-2002, 07:23 AM   #7
Koryon
Member
 
Join Date: Apr 2002
Location: Canada
Posts: 50
Koryon is on a distinguished road
 
Old 04-26-2002, 07:42 AM   #8
Sitral
New Member
 
Join Date: Apr 2002
Posts: 11
Sitral is on a distinguished road
Heh, won't quite fit what I'm working towards, Seth.  Previous examples were used to (hopefully) keep things simple.

Thanks again, Yui.  And thanks, Koryon.  Doesn't completely make sense, but when I need to learn it, it'll likely make it a bit easier.
 
Old 05-02-2002, 02:34 PM   #9
GenmaC
Member
 
Join Date: May 2002
Posts: 68
GenmaC is on a distinguished road
You could handle this with a double/single linked list too, but that's just the crack in my veins talking.
 



Help out a newbie? - Similar Threads
Thread Thread Starter Forum Replies Last Post
newbie crownrahul Tavern of the Blue Hand 1 02-04-2006 10:12 AM
Okay, this really is a newbie q. Rindu Newbie Help 1 12-24-2005 11:56 AM
Newbie Welcome... ozental Introduce Yourself 0 12-03-2004 11:27 AM
Newbie Looking for His Second MUD Walkingman Newbie Help 3 11-18-2003 01:30 PM
Newbie Demo Tavish Advanced MUD Concepts 9 04-28-2002 01:53 AM


All times are GMT -4.


Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Style based on a design by Essilor
Copyright Top Mud Sites.com 2022