[Home] [Downloads] [Search] [Help/forum]

Gammon Software Solutions forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  ROM
. -> [Folder]  Running the server
. . -> [Subject]  RT ASCII stuff...

Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?
(New message)
Subject: RT ASCII stuff...
Name:
Your forum user name.
Register forum user name
Password:
Your forum password.
Forgotten password?
Message:
Message to be posted (in English, please).
Forum codes:
Check this if your message uses 'forum codes' or templates (auto-detected for new posts).
Forum codes Templates

Save this message ...


Subject review (reverse sequence)

Pages: 1 2  

Posted by Nash   USA  (20 posts)  [Biography] bio
Date Sun 30 May 2004 07:21 AM (UTC)  quote  ]

Amended on Sun 30 May 2004 09:43 AM (UTC) by Nash

Message
actually.. somehow it works now, but... I get this:

In file included from /usr/include/bits/sigcontext.h:28,
from /usr/include/signal.h:313,
from comm.c:92:
/usr/include/asm/sigcontext.h:76: syntax error before numeric constant
/usr/include/asm/sigcontext.h:80: syntax error before '}' token


:(
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio   Moderator
Date Sun 30 May 2004 06:40 AM (UTC)  quote  ]
Message
What you should do is do as SMAUG does in order to read and write flags. Imitate what they have. SMAUG doesn't do it "weird", chances are, they do it "right". :)

Very seriously, you should learn C before you do something non-trivial like this. Your function looks like it's right, but chances are you're forgetting something somewhere else. What is the type of 'flags'?

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by Nash   USA  (20 posts)  [Biography] bio
Date Sun 30 May 2004 06:16 AM (UTC)  quote  ]

Amended on Sun 30 May 2004 06:23 AM (UTC) by Nash

Message
I have... smaug uses a structure to store flags, and reads/loads them all differently... I can paste in the functions.. but I'd have to know which you need to see ...I'm trying really hard to learn this and figure out the workings of it all, but it's quite hard to learn c on your own, thank ya for this.. but... yea smaug does it weird. So, in fwrite_flag, it should write out a 0 for each inactive flag, and a 1 for each active one, and then in fread_flag, do the reverse?

new fwrite_flag?->
for ( offset = 0, cp = buf; offset < 64; offset++ )
if ( flags & ( (long long)1 << offset ) )
{
*(cp++) = '1';
}
else
{
*(cp++) = '0';
}
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio   Moderator
Date Sun 30 May 2004 06:09 AM (UTC)  quote  ]
Message
How am I supposed to know if that output is correct or not? Besides, if it's wrong, there's only one reason: you must have made a mistake in your output code.

Forgive me for copy/pasting, but... Allow me to warn you again: what you are attempting to do is non-trivial and you seem to be a novice coder. I strongly suggest that you look at SMAUG's EXT_BV code. Have you done that yet?

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by Nash   USA  (20 posts)  [Biography] bio
Date Sun 30 May 2004 05:53 AM (UTC)  quote  ]
Message
altered that for loop, trying to make it work a bit better, and it sorta prints it in binary.. but it ends up looking like this!

#818
no name~
(no short description)~
(no long description)
~
~
human~
1111111111111111111111111111111111 0 0 0
0 0 0d0+0 0d0+0 0d0+0 none
0 0 0 0
0 0 0 0
stand stand none 0
0 0 medium unknown
F for 1111
F par 11111111111
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio   Moderator
Date Sun 30 May 2004 05:13 AM (UTC)  quote  ]
Message
With all due respect you can't cover C or Java in just a month if you've never done real programming before.

What that function is doing is writing out the letter constants that were given to the decimal constants. For instance, if the offset is zero, it will write A. If the offset is three, it will write D. If the offset is 26, it will write 'a'.

What this means is that you have an upper limit of 52=26*2 possible flags. If the system were more a little more intelligent, it wouldn't have such an upper limit.

You could write out the binary representation of the flag. That would be 64 characters, however. It would take up less memory to write out the decimal version. Only problem is that manipulating 64-bit numbers is harder than 32-bit numbers.

One problem is that you cast the bitshift to long and not long long. This won't work at all if your bitshift goes out of long range, which is clearly does since offset goes to 64.

Allow me to warn you again: what you are attempting to do is non-trivial and you seem to be a novice coder. I strongly suggest that you look at SMAUG's EXT_BV code. Have you done that yet?

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by Nash   USA  (20 posts)  [Biography] bio
Date Sun 30 May 2004 04:39 AM (UTC)  quote  ]

Amended on Sun 30 May 2004 04:48 AM (UTC) by Nash

Message
It means I suck with math, I'm better with more graphics type games, as opposed to thinking of the world in math functions, it's weird checks and word functions. I used to code vb and javascript, and the little c and j I did for a month, the former of which I'm trying to relearn! The function you point out writes letters to the designated file, which correspond to the different flags of a mob, apparently going based on the ascii of the upper/lower case letters... I don't understand totally how it works, but I know what it does.. it'd be more effective probably to write down 64 0's and then for each of those flags that's active, change its corresponding 0 to a 1, and then have it read in that way as well.. unless I have how it works wrong!
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio   Moderator
Date Sun 30 May 2004 04:10 AM (UTC)  quote  ]
Message
What is a 'logic programmer' as opposed to a 'normal programmer'? What language did you program in?

Do you understand what this is doing:

 for ( offset = 0, cp = buf; offset < 64; offset++ )
if ( flags & ( (long)1 << offset ) )
{
if ( offset <= 'Z' - 'A' )
*(cp++) = 'A' + offset;
else
*(cp++) = 'a' + offset - ( 'Z' - 'A' + 1 );
}

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by Nash   USA  (20 posts)  [Biography] bio
Date Sun 30 May 2004 03:32 AM (UTC)  quote  ]

Amended on Sun 30 May 2004 03:37 AM (UTC) by Nash

Message
I do understand bitmasks and binary, and I have coding knowledge, but I've been more of a logic programmer, and I'm porting my knowledge of other languages over to C, which is a transistion that's not being very easy for me to make.. I learn best by asking a lot of questions and this is just something I don't understand too well, sorry for bugging you for so much clarification. I don't think I totally understand it, but it did work, and it's whittled the errors down to when you save, it seems to print weird stuff


->Afg† 0 0 0<-
(and the weird holy cross looks like an a with a circle ontop of it in shell..)

It seems to save new mobs funny... that mob had the flags 'npc' and 'shaman', and printed the above... the code for saving is in olc_save.c and I think the following function...

char *fwrite_flag( long long flags, char buf[] )
{
char offset;
char *cp;

buf[0] = '\0';

if ( flags == 0 )
{
strcpy( buf, "0" );
return buf;
}

/* 64 -- number of bits in a long long */

for ( offset = 0, cp = buf; offset < 64; offset++ )
if ( flags & ( (long)1 << offset ) )
{
if ( offset <= 'Z' - 'A' )
*(cp++) = 'A' + offset;
else
*(cp++) = 'a' + offset - ( 'Z' - 'A' + 1 );
}

*cp = '\0';

return buf;
}



and it's read in by this..

long long fread_flag( FILE *fp)
{
int number;
char c;
bool negative = FALSE;

do
{
c = getc(fp);
}
while ( isspace(c));

if (c == '-')
{
negative = TRUE;
c = getc(fp);
}

number = 0;

if (!isdigit(c))
{
while (('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z'))
{
number += flag_convert(c);
c = getc(fp);
}
}

while (isdigit(c))
{
number = number * 10 + c - '0';
c = getc(fp);
}

if (c == '|')
number += fread_flag(fp);

else if ( c != ' ')
ungetc(c,fp);

if (negative)
return -1 * number;

return number;
}








this function also kinda stuck out to me...

long long fread_flag( FILE *fp)
{
int number;
char c;
bool negative = FALSE;

do
{
c = getc(fp);
}
while ( isspace(c));

if (c == '-')
{
negative = TRUE;
c = getc(fp);
}

number = 0;

if (!isdigit(c))
{
while (('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z'))
{
number += flag_convert(c);
c = getc(fp);
}
}

while (isdigit(c))
{
number = number * 10 + c - '0';
c = getc(fp);
}

if (c == '|')
number += fread_flag(fp);

else if ( c != ' ')
ungetc(c,fp);

if (negative)
return -1 * number;

return number;
}
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio   Moderator
Date Sun 30 May 2004 01:02 AM (UTC)  quote  ]
Message
"Code-alize"? :P

The BVxx is the way you're "supposed" to do the flags, i.e. proper bitshifts and not decimal constants.

Do you understand binary and how bitmasks work?

If I may say so, no offense but you're trying something rather difficult but don't seem to know much about coding. More likely than not you'll just get frustrated here. Have you looked into the extended bitvector system that SMAUG has like I suggested?

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by Nash   USA  (20 posts)  [Biography] bio
Date Sun 30 May 2004 12:50 AM (UTC)  quote  ]

Amended on Sun 30 May 2004 12:55 AM (UTC) by Nash

Message
hm... lost me on the bitshift :D

the closest thing found there was "#define BV31 (1 << 31)" which isn't used in the flags, apparently they use a table for the various flags and such... but I'm still learning to code-alize, and that's way way beyond me..
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio   Moderator
Date Sat 29 May 2004 06:58 AM (UTC)  quote  ]
Message
Well, for one, you need to change all functions that access the new format.

For two, typically you don't define these constants the way your MUD is... you define them as bitshifts. e.g. 1 << 32

That should remove the warnings, but I suggest you look at code that actually uses that technique e.g. SMAUG 1.4.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by Nash   USA  (20 posts)  [Biography] bio
Date Sat 29 May 2004 06:13 AM (UTC)  quote  ]
Message
Am I doing something wrong to define a longlong? It's my understanding you do simply 'long long <variable>;', it works except I get the following errornicities...

db.c:2068: warning: decimal constant is so large that it is unsigned
->if (IS_SET(mob->act,ACT_SHAMAN))<-

handler.c:2681: warning: decimal constant is so large that it is unsigned
->if (act_flags & ACT_SHAMAN ) strcat(buf, " shaman");<-

tables.c:106: warning: decimal constant is so large that it is unsigned
->{ "shaman", ff, TRUE },<-

and ACT_SHAMAN is set as 'ff' which is set as '2147483648'

I set the bit variable in act_flags to a long long, but it apparently don't like it... and... just wondering if I define longlongs wrong
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio   Moderator
Date Fri 28 May 2004 07:46 PM (UTC)  quote  ]
Message
I said 'long long', not 'long'. If you change to long you likely won't be changing anything since on many systems ints and longs are both of 32 bits.

You need to change:
- the variables that store the flags
- the macroes that read/write the flags
- the functions that save/load the flags to file

Proceed at your own risk, however :)

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by Nash   USA  (20 posts)  [Biography] bio
Date Fri 28 May 2004 02:35 PM (UTC)  quote  ]

Amended on Fri 28 May 2004 02:38 PM (UTC) by Nash

Message
I know how small integers are, just... they're used as 32 ones and zeroes to flag stuff in this case, so no matter what I'm limited to 32, but yes, it'd be nice to make a datastructure, but I really haven't the slightest clue how, and I probably won't be expanding it so much that I need more than 64 bits, but I apparently don't know which integers I wanna convert to long, and if it's just as easy as changing the variable from 'int whatever;' to 'long whatever;', but if ya have any explanation of applying a data structure to the various fields where it currently uses the bit-ness, I'd like to know..
[Go to top] 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.


5,135 views.

This is page 1, subject is 2 pages long: 1 2  [Next page]

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

[Home]

Written by Nick Gammon - 5K

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( http://www.gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Internet Contents Rating Association (ICRA) - 2K]    [Web site powered by FutureQuest.Net]