EXP problem in score

Posted by Ithildin on Sun 22 Feb 2004 03:35 AM — 17 posts, 62,107 views.

USA #0
here's what part of my score looks like:

PRACT: 2 Hitpoints: 20 of 37
EXP : 2000 Mana: 100 of 100


i want the Exp to look like this:

Xp Needed : 1750
Xp Current : 107

here's what my code looks like:


pager_printf_color(ch, "&CEXP  : &W%-9d    &CMana: &B%-5d &Cof &b%5d   &CMKills:  &W%5d    &CAutoLoot(&W%c&C)\n\r",
		ch->exp, ch->mana, ch->max_mana, ch->pcdata->mkills, xIS_SET(ch->act, PLR_AUTOLOOT) ? 'X' : ' ');


i'm not really sure what to fix here.

i tried this:


"&CEXP  : &W%-9d  &Cof %9d


but that doesn't work. any thoughts or suggestions?
USA #1
i've been tryin all sorts of things. could someone at least help me gain some knowledge of what the %-9d is and such? then i could probably just figure it out on my own.
Canada #2
Check your man page for format. That should tell you all you need to know in that context. The other option is show us exactly what you did, with the full code that didn't work, and HOW it didn't work. Did it crash, or display the wrong stuff?
USA #3
when i tried that code that i showed. it came up with this:

Exp : 2000 of 100 Mana 100 of 0

so it was confusing what i put in with the max_mana. i tried making a max_exp sh_int in mud.h but i still didn't know what those numbers were for. ie the %-9d and such.
Canada #4
Did you check the man page? "man format" will discribe the difference between "%-9d" and "%d". However, in the actual line, is your adding a nother print variable (%d, for example), you need to add something to fill in that info. Now, as for what to use, you need to look for code that might already utilize this, like do_level. Looking at the smaugfuss code, you need something like this:
pager_printf_color(ch, "&CEXP  : &W%-9d of %-9d   &CMana: &B%-5d &Cof &b%5d   &CMKills:  &W%5d    &CAutoLoot(&W%c&C)\n\r",
		ch->exp, exp_level(ch, ch->level+1) - ch->exp, ch->mana, ch->max_mana, ch->pcdata->mkills, xIS_SET(ch->act, PLR_AUTOLOOT) ? 'X' : ' ');


I added a %-9d, so I had to add something to print into it, which is the exp_level part.

That should work for you.
USA #5
thanks so much for you help. first of all, i'm not really sure what you mean by man page. but i did try what you said and it worked..but wasn't what i was needing.

it worked out like this

EXP : 2840 of 70

what i'm wanting it to say is:

EXP : 2840 of 2910

so i'm guessin i would add something somewhere.

ok, scratch that. here's what i did after that. i just deleted the - ch->exp part and it works fine.

Thanks.

i feel stupid, but could you explain what the man page is?
Canada #6
man stands for manual( I assume ). It will give you information you need on commands, code, functions, etc. You access it with "man <string>", in this case, "man format". You can scroll up and down(if it has enough text to not fit on your screen). This one tells you the command, a short description, an introduction, details on it, special notes from the author, and keywords for the man page. This explains the different between using -, +, 0, and #.

Hope that helps.
#7
Access it from where? I've never heard of this but if it does exist, that would be awesome. Score is next on my list, after fixing that who list.
Canada #8
You access it at your command prompt. You need to be using a *nix system, or cygwin with the man package.
#9
Man package? I'll have to look for that and make sure to download it. Thanks for the tip.
USA #10
i'm using windows version... :(

i tried cygwin once, but i couldn't get it to work right.

if i ever went back, would it be hard to switch from windows to cygwin?
#11
I really doubt that you'll be able to use the Windows version with Cygwin. If you download the original 1.4a code, though, and the Crypt library for Cygwin, you'll only have to change one or two simple things to get it working properly.
Canada #12
The win32 port SHOULD work in cygwin IF they did it properly and used defines, which I beleive they did. Best way is to try it.
#13
I downloaded the man package with Cygwin but there's no page on 'format'. Is there another keyword for it?

Anyways, WIN32 ifdefs don't work with Cygwin, from what I've seen. For example, to compile SMAUG 1.4a with Cygwin, you need to #define NOCRYPT -outside- of the WIN32 ifdef even though it's defined inside it.
Australia Forum Administrator #14
Try: man 3 printf

The Windows version should compile under Unix, the one I did had the appropriate defines in it.

The important thing with printf is you need to tell it *how* to print something and also *what* to print.

eg.


int myage = 5;

printf ("my age is %i", myage);


The %i tells print to print an integer and "myage" is the integer to print.

Now if you were going to add something (eg, myheight) then you need to add another %i *and* the variable containing the height, like this:



int myage = 5;
int myheight = 100;

printf ("my age is %i and my height is %i", myage, myheight);



Things like the %9d or %-9d are extra formatting. In this case the "9" means "make it 9 characters wide" and the "-" changes from left to right-justification (or the other way around, I can never remember which).

Australia Forum Administrator #15
Here are the types from the man page:


TYPE specifies what kind of conversion `printf' performs.  Here is
a table of these:

`%'
     prints the percent character (`%')

`c'
     prints ARG as single character

`s'
     prints characters until precision is reached or a null
     terminator is encountered; takes a string pointer

`d'
     prints a signed decimal integer; takes an `int' (same as `i')

`i'
     prints a signed decimal integer; takes an `int' (same as `d')

`o'
     prints a signed octal integer; takes an `int'

`u'
     prints an unsigned decimal integer; takes an `int'

`x'
     prints an unsigned hexadecimal integer (using `abcdef' as
     digits beyond `9'); takes an `int'

`X'
     prints an unsigned hexadecimal integer (using `ABCDEF' as
     digits beyond `9'); takes an `int'

`f'
     prints a signed value of the form `[-]9999.9999'; takes a
     floating point number

`e'
     prints a signed     value of the form
     `[-]9.9999e[+|-]999'; takes a floating point number

`E'
     prints the same way as `e', but using `E' to introduce the
     exponent; takes a floating point number

`g'
     prints a signed value in either `f' or `e' form, based on
     given value and precision--trailing zeros and the decimal
     point are printed only if necessary; takes a floating point
     number

`G'
     prints the same way as `g', but using `E' for the exponent if
     an exponent is needed; takes a floating point number


USA #16
THanks Nick, i'll put that into a notepad file for later use.