Re: scope again
From: Joe (mail_at_annuna.com)
Date: 03/22/04
- Next message: Joe: "Re: scope again"
- Previous message: hubert depesz lubaczewski: "Re: simple text matching problem"
- In reply to: Bob Walton: "Re: scope again"
- Next in thread: Joe: "Re: scope again"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 22 Mar 2004 06:48:53 GMT
Bob Walton wrote:
> Joe wrote:
>
>> This class still will not work. I have stripped the class down to the
>> basics. I know about the style issue so this is basically bare bones.
>> package Space;
>>
>>
>> #spaces of the grid
>>
>> sub new{
>> my $space = {
>> loc => $_[0],
>> char => 0
>> };
>>
>> bless $space, 'Space';
>>
>> print $space->{loc}; <-- prints here.
>> return $space;
>> }
>>
>> sub fchsym{ #returns the symbol for map printing.
>>
>> print "k"; <-prints this so I know that it gets accessed.
>> print "$space->{loc}"; < -won't print these data mbembers. Dosn't print anything.
>
>
> --------^-------------^
> Inside quotes, the variable $space will be interpolated. If $space
> contains the string "Pluto", you would get:
>
> Pluto->{loc}
>
> printed. Interpolation does not evaluate operators. This is different
> than the code in your first post, which did not contain this particular
> error. Have you been copy/pasting your code, or retyping it in your
> posts? Please *please* copy/paste it.
>
I don't get an error, I get no outout. Once I can get some output, I
can print the output in the GUI. I have tried warnings and get nothing.
I will
>
>> print "$space->{char}";
>
>
> --------^--------------^
> same thing
>
>
>> return $space->{loc};
>> }
>>
> ...
>
>
> Well, other than the above, I'll bet it's something in the way you're
> calling your module. Here is a complete example that should work if
> copy/paste/executed (and note: please pay attention to what the various
> replys in your previous thread said about OO-programming in Perl -- they
> were right on -- this code is your code almost verbatim, and is *not*
> necessarily How It Should Be Done [all one file]:
>
> use warnings;
> use strict;
> my $s=new Space('location');
> print "main program...\n";
> print Space::fchsym();
>
> package Space;
>
> my $space;
>
> #spaces of the grid
>
> sub new{
> $space = {
> loc => $_[1],
> char => 0
>
> };
>
> print $space->{loc};
> bless $space, 'Space';
> return $space;
> }
>
> sub fchsym{ #returns the symbol for map printing.
>
> print $space->{loc};
> return $space->{loc};
> }
> 1;
>
>
> When run, that should print:
>
> D:\junk>perl junk440.pl
> locationmain program...
> locationlocation
> D:\junk>
>
> The first 'location' was from the new method; the second was from sub
> fchsym, and the third was from the print in package main.
>
> Does this give you these same results when copy/paste/executed? If so,
> you have a starting point for figuring out what is going wrong.
I realy don't care about it printing. Most of what I am posting is
debugging flags. All I want to know is why a variable in a pacahge
won't transfer from one sub to another in the sam package there is what
the C++ code looks like and what I am trying to do is return a character
for a map.
This Object is the spaces of the
map. This holds all the things
on the map. */
class space{
int mony; /* Hold money */
char loc; /* The Map char */
char monchr; /* Symbol for money */
char psym; /* The symbol for the player. */
bool sflag; /* Has the space been mapped?
Used for drawing the map */
vector<prize> przs; /* Holds Prizes on the map */
char space::rchr(){
sflag = true;
if (psym != '/'){return psym;}
if (przs.size() > 0){return przs[0].gsymbol(); }
if (mony > 0){return monchr;}
return loc;
}
$space->{loc} is a simple character. containing a H or . I have tried it
with and without quotes.
I will try your advice. I am pretty good with perl and have been
working with C++. I have a working version of my game it is a simple
role playing game. I am currently trying to do an update using my
spaces as objects instead of a grid of characters. I am working in perl
becuase I can understand TK I have no clue on how to do GUIs with C++.
I have seen GUI pages with C++ but I can't find any good books on doing
GUIs with C++. I don't have my game that I am working on posted because
I can't get this simple object to work.
my programs are posted at www.annuna.com/perl5
I can do the grid of objects in C++ and the GUI in perl. I realy
thought this would be pretty easy, perl is much esaier than C++ but
programming is programming.
- Next message: Joe: "Re: scope again"
- Previous message: hubert depesz lubaczewski: "Re: simple text matching problem"
- In reply to: Bob Walton: "Re: scope again"
- Next in thread: Joe: "Re: scope again"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|