Author Topic: ZAPM - some trouble  (Read 26618 times)

eit_cyrus

  • Newcomer
  • Posts: 4
  • Karma: +0/-0
    • View Profile
    • zapm.org
    • Email
Re: ZAPM - some trouble
« Reply #15 on: February 20, 2011, 11:14:40 PM »
It appears to be an older VC project file, so maybe there are differences let's say in Windows XP (possibly the platform zapm was programmed) and Windows 7 related to that input routine. Who knows. Just looking at global.h tells that zapm source code is poor quality.

poor qaualalitiy??!!!!
poor qualiaity????  WHO DAERS to imppeach teh codding skillzz of EIT_CYRUS!?!?!  ZAPM was not intended to be complied by teh likes of GRIID BUGZ like yuo using soem tin can crock box hoem computter!!! 

I suggets yuo upgraed your computer to hthte to teh propar system requiremements!!  ZAPM is develeloped on  a REALL WORKSTAITION with SERIUOUS specificiations!!!!:
]

  • 17 hot swappable intel pentiumm VI COre iXII procoessors!! wiht hypar thearding !!
  • 18 jiggaabytes of RAM
  • DUAL USB 4.2 keybaords
  • ATI Radoen 9500ASC graphicis adaapter
  • 6000 TB RAID 22 REDUNDENT REDUNDANT DISK DRIEV ARAY!!![/ii]
[/size]

Ex

  • IRC Communications Delegate
  • Rogueliker
  • ***
  • Posts: 313
  • Karma: +0/-0
    • View Profile
Re: ZAPM - some trouble
« Reply #16 on: February 21, 2011, 12:57:22 AM »
Yeah guys, I have this exact setup, and it compiles just fine!  ;D

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: ZAPM - some trouble
« Reply #17 on: February 21, 2011, 07:31:16 AM »
I'm not sure if this causes the bug, but I think testing like

if (value)

or

if (!value)

should be used only with boolean type. Anyway, it's just a guess, could be something else. Maybe it's some kind of compiler dependent stuff and fails to work correctly in proper compilers like VC++.

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: ZAPM - some trouble
« Reply #18 on: February 21, 2011, 08:03:12 AM »
I had some time so I fixed the bug by refactoring that section of code. I also removed goto command, because those are bad. And added some comments. This code is in main.cpp.

Code: [Select]
I->showVersion ();

bool name_ok=true; //name is ok by default

//if no name was given yet
if (name==0)
{
for (int tries=0; tries<5; tries++)
{
//get computer's name as default name
name = getenv ("USER");
if (name==0) name = getenv ("USERNAME");

//input player's name
I->p ("Welcome to ZAPM!");
I->getStr (namebuf, HERO_NAME_LENGTH+1, "What is your name?", name);
I->pageLog ();

//check if the name is valid
if (nameOK(namebuf)==1)
{
name=namebuf;
name_ok=true;
break;
}
else name_ok=false; //set the name invalid and try again for five times
}
}

if (name_ok)
{
//load or play new game
if (0 == loadGame (name) || 0 == newGame (name))
{
I->p ("Welcome to \"ZapM\".  Press '?' for help.");
I->p ("Please submit bug reports at http://zapm.org/bb/");
if (GodMode) I->p ("God Mode is on.");
gameLoop ();
}
}
else
{
//failed to input a proper name
I->p ("Too many tries!");
I->pause ();
I->p ("");
}

    delete I;
« Last Edit: February 21, 2011, 08:05:11 AM by Krice »

Ex

  • IRC Communications Delegate
  • Rogueliker
  • ***
  • Posts: 313
  • Karma: +0/-0
    • View Profile
Re: ZAPM - some trouble
« Reply #19 on: February 21, 2011, 09:57:06 AM »
That's a good version, Krice. The original code is a little strange, for instance, why do we check for the name 5 times? Is the user going to endlessly try to type in invalid names? And what counts as an invalid name? The only invalid name I can think of is one that is below or above a certain size. Anyway, here's what I was thinking:

Code: [Select]
I->showVersion ();

//get computer's name as default name

if(!name) //Thanks Krice! :D
if(getenv("USER"))
name=getenv("USER");
else if(getenv("USERNAME"))
name=getenv("USERNAME");

while(true) {
//input player's name
I->p ("Welcome to ZAPM!");
I->getStr (namebuf, HERO_NAME_LENGTH+1, "What is your name?", name);
I->pageLog ();

//check if the name is valid
if (nameOK(namebuf))
{
name=namebuf;
break;
}
}

//load or play new game
if (!loadGame (name) || !newGame (name)) //This originally assumed that loadGame and newGame return a non-zero value on success, which wasn't the case.
{
I->p ("Welcome to \"ZapM\".  Press '?' for help.");
I->p ("Please submit bug reports at http://zapm.org/bb/");
if (GodMode) I->p ("God Mode is on.");
gameLoop ();
}
    delete I;

Also, in response to the questions, ! will work with things that you wouldn't expect it to, because ! checks to see whether or not the operand is 0 (which is particularly useful since NULL = 0). If the operand is 0, then ! returns true. If the operand is non-zero, then ! returns false. For instance, !0 is true, while !1, !2, !3, !'a', and !"hello" are all false.

In C/C++, the if operator functions similarly: zero is false, non-zero is true. This allows for things like if( this_string_pointer_isnt_null ) printf("%s",the_string_mentioned_before); Despite how it may look, this actually works fine whether the string pointer is NULL or not (provided that if the pointer is not NULL that it points to a valid memory location, of course).

EDIT: I just downloaded ZAPM to see what problems might come up in compiling it, but it compiled just fine. There were less warnings than I see on my own code. I use MSVC++ 2008 Express, which is free. Even the name prompt works. Mingw32 might not like that ZAPM is defining classes without declaring what they are. If that's the case, you should just be able to delete those lines and move the class definitions around to get it to work.

EDIT 2: Thanks Krice! Fixed. :)
« Last Edit: February 21, 2011, 10:51:50 AM by Elig »

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: ZAPM - some trouble
« Reply #20 on: February 21, 2011, 10:24:45 AM »
And what counts as an invalid name?

nameOK function is checking the name. I didn't look at that carefully, but it doesn't matter, I trust it works. Also, I think you forgot (in your version) that 'name' can already be set from command line (check earlier code!). That's why the code starts with if (name==0) check and skips it entirely if name is set.

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: ZAPM - some trouble
« Reply #21 on: February 21, 2011, 10:28:38 AM »
Despite how it may look, this actually works fine

Didn't work fine in this case!

Ex

  • IRC Communications Delegate
  • Rogueliker
  • ***
  • Posts: 313
  • Karma: +0/-0
    • View Profile
Re: ZAPM - some trouble
« Reply #22 on: February 21, 2011, 10:32:46 AM »
Despite how it may look, this actually works fine

Didn't work fine in this case!
Where in this case?

EDIT: Ah, I found the problem :) Here's the fixed code, tested in game:

Code: [Select]
 I->showVersion ();

//get computer's name as default name

if(!name) //Thanks Krice! :D
if(getenv("USER"))
name=getenv("USER");
else if(getenv("USERNAME"))
name=getenv("USERNAME");

while(true) {
//input player's name
I->p ("Welcome to ZAPM!");
I->getStr (namebuf, HERO_NAME_LENGTH+1, "What is your name?", name);
I->pageLog ();

//check if the name is valid
if (nameOK(namebuf))
{
name=namebuf;
break;
}
}

//load or play new game
if (!loadGame (name) || !newGame (name)) // Turns out that these return 0 on success
{
I->p ("Welcome to \"ZapM\".  Press '?' for help.");
I->p ("Please submit bug reports at http://zapm.org/bb/");
if (GodMode) I->p ("God Mode is on.");
gameLoop ();
}
    delete I;
It wasn't working because loadGame and newGame return 0 on success. Also, the original program shows the name editor screen even if given a name, so I updated that, too.
« Last Edit: February 21, 2011, 10:41:52 AM by Elig »

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: ZAPM - some trouble
« Reply #23 on: February 21, 2011, 11:07:48 AM »
Where in this case?

If you compile the original code the name input doesn't work (for some reason). I guess it must have something to do with those !checks with other than booleans, because with the refactored code I posted the input works and you can proceed to play the game.

ps. I think you "fixed" the code wrong again: the entire code section must be skipped if 'name' is given in command line. Also, the problem is not in the return values of newGame or loadGame which return int. Stop checking other than booleans with !.
« Last Edit: February 21, 2011, 11:11:51 AM by Krice »

Ex

  • IRC Communications Delegate
  • Rogueliker
  • ***
  • Posts: 313
  • Karma: +0/-0
    • View Profile
Re: ZAPM - some trouble
« Reply #24 on: February 21, 2011, 11:17:40 AM »
Where in this case?

If you compile the original code the name input doesn't work (for some reason). I guess it must have something to do with those !checks with other than booleans, because with the refactored code I posted the input works and you can proceed to play the game.

ps. I think you "fixed" the code wrong again: the entire code section must be skipped if 'name' is given in command line. Also, the problem is not in the return values of newGame or loadGame which return int. Stop checking other than booleans with !.
The fixed code works fine, my original fix wasn't working because newGame and loadGame needed ! to be checked. Checking stuff with ! is a time tested, tried, and true method of programming in C/C++. It is perfectly valid, and works fine in this case. Also, skipping the name editor if name is given at the command line is not totally nesssisary, but if you want it, then just put brackets around everything before the new/loadGame stuff. My code works fine, ! has nothing to do with it. In any event, my fix works. Don't tell me what to do when you clearly don't know C/C++ as well as I do.
« Last Edit: February 21, 2011, 11:19:33 AM by Elig »

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: ZAPM - some trouble
« Reply #25 on: February 21, 2011, 12:21:57 PM »
my original fix wasn't working because newGame and loadGame needed ! to be checked.

They return int, you use ! with booleans. Also, try to get that if you give the name from command line (using -u username) it's already check with nameOK. Scroll up to see the previous code. Now, if you don't skip the ENTIRE code section asking player's name it's going to ask the name AGAIN even if you entered it in command line. Try to get it, finally!

Psiweapon

  • Rogueliker
  • ***
  • Posts: 334
  • Karma: +0/-0
  • Im in ur rougeliekz, pixelling ur tielz!
    • View Profile
    • I Lovemaking Tiles
Re: ZAPM - some trouble
« Reply #26 on: February 21, 2011, 03:59:59 PM »
ZOMG TEH DRAMA!!!!

I´ll proceed to read the thread and   :D
The invisible hand is a lie, the fiendish dogma of the market cultists. Lest the apostasy grows strong, their blood god will devour each and everyone, pious and infidel alike.

Psiweapon

  • Rogueliker
  • ***
  • Posts: 334
  • Karma: +0/-0
  • Im in ur rougeliekz, pixelling ur tielz!
    • View Profile
    • I Lovemaking Tiles
Re: ZAPM - some trouble
« Reply #27 on: February 21, 2011, 04:04:48 PM »
Also I will check your fixes, I HOEP TEHY DONT SPLODE MY CAMPUTER!!!!7!!7
The invisible hand is a lie, the fiendish dogma of the market cultists. Lest the apostasy grows strong, their blood god will devour each and everyone, pious and infidel alike.

Psiweapon

  • Rogueliker
  • ***
  • Posts: 334
  • Karma: +0/-0
  • Im in ur rougeliekz, pixelling ur tielz!
    • View Profile
    • I Lovemaking Tiles
Re: ZAPM - some trouble
« Reply #28 on: February 21, 2011, 04:12:52 PM »
Fixes work nice, but 0.8.3 keeps crashing when a barrel explodes  ::)
The invisible hand is a lie, the fiendish dogma of the market cultists. Lest the apostasy grows strong, their blood god will devour each and everyone, pious and infidel alike.