missing operand and also crashing

November 4, 2014 at 13:35:11
Specs: Windows 8
Ok so this is the same question with the new code...

:Beginning
@echo off
cls
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo Welcome To Cookie Clicker!
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo.
echo This is a buffer for the game, just to make sure all the folders are created...
echo.
echo Below this text is a box containing all the errors, I try to keep them contained
echo so when sommthing isent working right or I need help, this is where I goto look.
echo.
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cd C:\Users\Games\Desktop\Game_Info
set /p Cookie_Count=<Cookie_Clicker.txt
set /a Oven=<Oven(s).txt
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pause
goto Start

:Start
title Cookie Clicker!
cls
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo Welcome To Cookie Clicker!
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo.
echo 1) Start
echo 2) Store
echo 3) Info
echo 4) Cridits
echo.
echo You Have Baked %Cookie_Count% Cookies's!
echo.
set /P Select= Please Choose One Of The Options:

if %Select%==1 goto Game
if %Select%==2 goto Store

:Game
cls
cd C:\Users\Games\Desktop\Game_Info
set /p Cookie_Count=<Cookie_Clicker.txt

echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo Just Press Any Key To Start
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo.
echo.
echo You Have Baked %Cookie_Count% Cookies's!
echo.
pause
if %Oven%==0 set /a Cookie_Count=%Cookie_Count%+1
if %Oven%==1 set /a Cookie_Count=%Cookie_Count%+10
if %Oven%==2 set /a Cookie_Count=%Cookie_Count%+20
if %Oven%==3 set /a Cookie_Count=%Cookie_Count%+30
if %Oven%==4 set /a Cookie_Count=%Cookie_Count%+40
if %Oven%==5 set /a Cookie_Count=%Cookie_Count%+50
if %Oven%==6 set /a Cookie_Count=%Cookie_Count%+60
if %Oven%==7 set /a Cookie_Count=%Cookie_Count%+70
if %Oven%==8 set /a Cookie_Count=%Cookie_Count%+80
if %Oven%==9 set /a Cookie_Count=%Cookie_Count%+90
if %Oven%==10 set /a Cookie_Count=%Cookie_Count%+100
del Cookie_Clicker.txt
@echo %Cookie_Count% >> Cookie_Clicker.txt
goto Game
:Store
@echo off
title Store
cls
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo Welcome To The Store
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo.
echo Welcome to the store, with your cookies you can trade for goods!
echo.
echo 1) Oven ( Each one bought adds ten cookies per batch )
echo Cost: 1000 Cookies
echo 2)
echo 3)
echo 4)
echo 5)
echo.
echo type "back" to goto the main menu
echo.
if %Oven%==1 echo You have 1 Oven
if %Oven%==2 echo You have 2 Ovens
if %Oven%==3 echo You have 3 Ovens
if %Oven%==4 echo You have 4 Ovens
if %Oven%==5 echo You have 5 Ovens
if %Oven%==6 echo You have 6 Ovens
if %Oven%==7 echo You have 7 Ovens
if %Oven%==8 echo You have 8 Ovens
if %Oven%==9 echo You have 9 Ovens
if %Oven%==10 echo You have 10 Ovens
if else echo You have no Ovens
set /P Buy= Please Choose One...

cd C:\Users\Games\Desktop\Game_Info
if %Buy%==1 set /a Oven=%Oven%+1
set /a Oven=<%Oven(s)%.txt
del Oven(s).txt
if %Buy%==1 @echo %Oven% >> Oven(s).txt
if %Buy%==1 set /a %Cookie_Count%-1000
goto Start

so, whats wrong


See More: missing operand and also crashing

Report •


#1
November 4, 2014 at 14:59:05
For others, I assume this is the "same question" to which the poster refers:
http://www.computing.net/answers/pr...

Always pop back and let us know the outcome - thanks


Report •

#2
November 4, 2014 at 17:17:47
After reading my previous answer, I realized it was convoluted and confusing. My apologies. To read one line from a file (in this example: 'test.txt'):
set /p example=<test.txt
echo line one of 'test.txt' is:%example%

anywhere you have something like this:
set /a Oven=<Oven(s).txt

It will fail, because you need to use like:
set /p Oven=<Oven(s).txt

message edited by nbrane


Report •

#3
November 5, 2014 at 14:57:43
Well, you got rid of the dreaded missing operand, and for that I thank you but it still crashes when I add to the cookie count

Report •

Related Solutions

#4
November 5, 2014 at 17:11:00
This won't work:
if %Buy%==1 set /a %Cookie_Count%-1000

This will:
if %Buy%==1 set /a Cookie_Count-=1000
or, consistant with your prior usage:
if %Buy%==1 set /a Cookie_Count=%cookie_count%-1000
but not:
This won't work:
if %Buy%==1 set /a %Cookie_Count%-1000

This will:
if %Buy%==1 set /a Cookie_Count-=1000
or, consistant with your prior usage:
if %Buy%==1 set /a Cookie_Count=%cookie_count%-1000
nor will this:
if %Buy%==1 set /a %Cookie_Count%=%cookie_count%-1000

because the var. on the left of the equals has percents, and it should not.
Un-percented name refers to the variable's storage space. Percented name refers to the contents of that storage space. Very Important Distinction, basic to all programming. If you have a crate that says "Florida Oranges", but you open it and find Carolina Apples, then you will see: the variable name is "oranges", the variable content, totally independant of the name, happens to be apples, but anything else, including oranges, or just empty space, could be stored in the crate.

message edited by nbrane


Report •

#5
November 6, 2014 at 14:32:16
Thanks, I replaced the code and it works, but when I am in the ":Game" part of the running program it crashes when I add to the Cookie_Count.

Report •

#6
November 20, 2014 at 17:45:13
:Beginning
@echo off
cls
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo Welcome To Cookie Clicker!
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo.
echo This is a buffer for the game, just to make sure all the folders are created...
echo.
echo Below this text is a box containing all the errors, I try to keep them contained
echo so when sommthing isent working right or I need help, this is where I goto look.
echo.
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cd C:\Users\Games\Desktop\Game_Info
set /p Cookie_Count=<Cookie_Clicker.txt
set /p Oven=<Oven(s).txt
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pause
goto Start

:Start
title Cookie Clicker!
cls
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo Welcome To Cookie Clicker!
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo.
echo 1) Start
echo 2) Store
echo 3) Info
echo 4) Cridits
echo.
echo You Have Baked %Cookie_Count% Cookies's!
echo.
set /P Select= Please Choose One Of The Options:

if %Select%==1 goto Game
if %Select%==2 goto Store

:Game
cls
cd C:\Users\Games\Desktop\Game_Info
set /p Cookie_Count=<Cookie_Clicker.txt

echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo Just Press Any Key To Start
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo.
echo.
echo You Have Baked %Cookie_Count% Cookies's!
echo.
pause
if %Oven%==0 set /a Cookie_Count=%Cookie_Count%+1
if %Oven%==1 set /a Cookie_Count=%Cookie_Count%+10
if %Oven%==2 set /a Cookie_Count=%Cookie_Count%+20
if %Oven%==3 set /a Cookie_Count=%Cookie_Count%+30
if %Oven%==4 set /a Cookie_Count=%Cookie_Count%+40
if %Oven%==5 set /a Cookie_Count=%Cookie_Count%+50
if %Oven%==6 set /a Cookie_Count=%Cookie_Count%+60
if %Oven%==7 set /a Cookie_Count=%Cookie_Count%+70
if %Oven%==8 set /a Cookie_Count=%Cookie_Count%+80
if %Oven%==9 set /a Cookie_Count=%Cookie_Count%+90
if %Oven%==10 set /a Cookie_Count=%Cookie_Count%+100
del Cookie_Clicker.txt
@echo %Cookie_Count% >> Cookie_Clicker.txt
goto Game
:Store
@echo off
title Store
cls
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo Welcome To The Store
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo.
echo Welcome to the store, with your cookies you can trade for goods!
echo.
echo 1) Oven ( Each one bought adds ten cookies per batch )
echo Cost: 1000 Cookies
echo 2)
echo 3)
echo 4)
echo 5)
echo.
echo type "back" to goto the main menu
echo.
if %Oven%==1 echo You have 1 Oven
if %Oven%==2 echo You have 2 Ovens
if %Oven%==3 echo You have 3 Ovens
if %Oven%==4 echo You have 4 Ovens
if %Oven%==5 echo You have 5 Ovens
if %Oven%==6 echo You have 6 Ovens
if %Oven%==7 echo You have 7 Ovens
if %Oven%==8 echo You have 8 Ovens
if %Oven%==9 echo You have 9 Ovens
if %Oven%==10 echo You have 10 Ovens
if else echo You have no Ovens
set /P Buy= Please Choose One...

cd C:\Users\Games\Desktop\Game_Info
if %Buy%==1 set /a Oven=%Oven%+1
set /a Oven=<%Oven(s)%.txt
del Oven(s).txt
if %Buy%==1 @echo %Oven% >> Oven(s).txt
if %Buy%==1 set /a Cookie_Count=%cookie_count%-1000
goto Start

This is the current code


Report •

#7
November 20, 2014 at 18:55:22
so far, all I found wrong other than unresolved conditionals was you need to initialize the variables before using them. Before these lines:
cd C:\Users\Games\Desktop\Game_Info
set /p Cookie_Count=<Cookie_Clicker.txt
set /p Oven=<Oven(s).txt

add:
set cookie_count=0
set oven=0
to get rid of the errormessages, modify the two lines above to this:

set /p Cookie_Count=<Cookie_Clicker.txt 2>nul||set cookie_count=0
set /p Oven=<Oven(s).txt 2>nul||set oven=0


Report •

#8
November 21, 2014 at 07:30:48
I'm not sure if this is correct but I see that your answer says "set oven=0" I don't want to set the oven count to zero every time I open the program, I want it to be like you can resume with all your progress saved every time you play

Report •

#9
November 21, 2014 at 10:50:39
Ah, that is a "pre-set", prior to loading data from the file. If you run the batch, you will see it maintains the count. The only reason for this is when the program is run for the very first time, and there are no existing files. I offered the alternative:

set /p Cookie_Count=<Cookie_Clicker.txt 2>nul||set cookie_count=0
set /p Oven=<Oven(s).txt 2>nul||set oven=0
This sets the variable IF the file exists, and if it does not, sets var to zero.
Also, I forgot to fix this:
if else echo You have no Ovens
won't work, there is no syntax like that. Here's the fix:
...
echo type "back" to goto the main menu
echo.
:: fixed here
set /a oven+=0
if %oven%==0 echo you have zero ovnes
if %Oven%==1 echo You have 1 Oven
if %Oven%==2 echo You have 2 Ovens
...
etc.
the logic errors are legion, but it will be up to you to debug and repair them, otherwise it would not be your program. You need to learn how to debug scripts when you get errors, and study the syntax of IF, SET and FOR, and/or find an able assistant or tutor. That's beyond my scope on this forum. good luck


Report •


Ask Question