[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [pbmserv-dev] help with Get/Set Options in game.cpp



On Sun, Aug 25, 2002 at 11:58:08AM -0500, Douglas Zander wrote:
> should this work?  (it doesn't when I tried it)
> 
> fencetype = GetOption("fences","thinfences");
> gridtype = GetOption("grid","dots");

Nope.   The first call to GetOption() stops when it hits the line

0....'....1....'.
dzander1:fences:thickfences

and returns a pointer to the 't' in thickfences  (offset 16 from the start)

The second call Overwrites the buffer inside the GetOptions function, and
stops when it hits

0....'....1....'.
dzander1:grid:crosses

and returns a pointer to the c in crosses (offset 14 from the start).

If you happen to look at the contents of fencetype now... it's
"osses"  (offset 16 in the new buffer)

>  it comes out to fencetype equal to ('osses')  (why???)
> 
> what exactly do you mean by "COPY the string..."???

Change your code to save the value....

char fence[256];
char *fencetype = GetOption("fences","thinfences");
strcpy(fence, fencetype);                               // save it

char grid[256];
char *gridtype = GetOption("grid","dots");
strcpy(grid, gridtype);                                 // save it



> On Sun, 25 Aug 2002, Richard Rognlie wrote:
> 
> > It's a static variable issue, I'd bet.
> > 
> > we return a pointer to inside the static char[] space.  If you've done
> > a subsequent call to GetOption, the earlier value is no longer valid.
> > 
> > you need to COPY the string returned from GetOption() before you call it
> > again.
> > 
> > On Sun, Aug 25, 2002 at 11:20:01AM -0500, Douglas Zander wrote:
> > > I believe there is an error in the game.cpp file.  Here is what is happening.
> > > In this program I am working on (Quory/Quoridor) I allow two options to be
> > > set: one option is grid (of either 'dots' or 'crosses') and the other option
> > > is fences (of either 'thinfences' or 'thickfences')  Now here is the
> > > Quory.options file:
> > > 
> > > dzander1:grid:crosses
> > > dzander1:fences:thickfences
> > > 
> > > When I ask for the fence thickness I get the correct value ('thickfences')
> > > but when I ask for the grid type I get this ('s:thickfences')
> > > Something is wrong  with the game::GetOption(char *, char *) routine!!!
> > > Notice that the value of 's:thickfences' starts at exactly where the 'c'
> > > in the word 'crosses' would start (it lines up directly below the point
> > > where the function would have retrieved the word 'crosses'.  Does this
> > > make sense?  So I think what is happening is the function game::GetOption()
> > > is retrieving the 15th character of the wrong line! (15th onward to EOL)  
> > > The function is too confusing for me to figure it out what is wrong.  
> > > Would one of you kind programmers help out?  TIA
> > > 
> > > --
> > >  Douglas Zander
> > > 
> > > 
> > > 
> > > 
> > > To unsubscribe, send a message to esquire@gamerz.net with
> > > 	unsubscribe pbmserv-dev@gamerz.net
> > > as the BODY of the message.  The SUBJECT is ignored.
> > > 
> > 
> > -- 
> >  /  \__  | Richard Rognlie / Sendmail Ninja / Gamerz.NET Lackey
> >  \__/  \ | http://www.gamerz.net/rrognlie/    <rrognlie@gamerz.net>
> >  /  \__/ | No trees were killed in the sending of this message. 
> >  \__/    | However, a great many instructions were executed.
> > 
> > 
> > To unsubscribe, send a message to esquire@gamerz.net with
> > 	unsubscribe pbmserv-dev@gamerz.net
> > as the BODY of the message.  The SUBJECT is ignored.
> > 
> 
> 
> 
> --
>  Douglas Zander
> 
> 
> 
> 
> To unsubscribe, send a message to esquire@gamerz.net with
> 	unsubscribe pbmserv-dev@gamerz.net
> as the BODY of the message.  The SUBJECT is ignored.
> 

-- 
 /  \__  | Richard Rognlie / Sendmail Ninja / Gamerz.NET Lackey
 \__/  \ | http://www.gamerz.net/rrognlie/    <rrognlie@gamerz.net>
 /  \__/ | No trees were killed in the sending of this message. 
 \__/    | However, a great many instructions were executed.