Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Variable has no value...
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Gilby101




PostPosted: Sat Oct 07, 2006 12:33 pm   Post subject: Variable has no value...

I am making a Risk Based, text only, game. I' am having the same problem, I try to run my program, and when I get to line 279, It says that the variable has no value, anyone have a solution? Thanks.



Code:

%A Risk based game, it is turn based, and can involve up to 4 players %"RBG"
%Kristian Gilbert
%10/05/2006/

var name1, name2, name3, name4 : string

var player1, player2, player3, player4 : string

var continent1, continent2, continent3, continent4, continent5, continent6 : int

var NorthAmerica,SouthAmerica,Europe,Asia,Africa,Oceania : int

var choice1,choice2,choice3,choice4 : int

var p1choice1, p1choice2, p1choice2a, p1choice2all, p1choice3, p1choice4 : string

var p2choice1, p2choice2, p2choice2a, p2choice2all, p2choice3, p2choice4 : string

var p3choice1, p3choice2, p3choice2a, p3choice2all, p3choice3, p3choice4 : string

var p4choice1, p4choice2, p4choice2a, p4choice2all, p4choice3, p4choice4 : string

var n1choice1, n1choice2, n1choice3, n1choice4 : string

var n2choice1, n2choice2, n2choice3, n2choice4 : string

var n3choice1, n3choice2, n3choice3, n3choice4 : string

var dice1, dice2 : int





dice1 := Rand.Int (1,18)

dice2 := Rand.Int (1,12)

NorthAmerica := 1

SouthAmerica := 2

Europe := 3

Asia := 4

Africa := 5

Oceania := 6






put "Player1 what is your name?"

get name1

put "Player2 what is your name?"

get name2

put "Player3 what is your name?"

get name3

put "Player 4 what is your name?"

get name4

cls






put "Player1 pick your continent"

put "Pick beetween the following continents: "

put "North America(1), South America(2), Europe(3), Asia(4), Africa(5), Oceania(6)"

get continent1

if continent1 = NorthAmerica then
put "You have selected North America"
end if

if continent1 = SouthAmerica then
put "You have selected South America"
end if

if continent1 = Europe then
put "You have selected Europe"
end if

if continent1 = Asia then
put "You have selected Asia"
end if

if continent1 = Africa then
put "You have selected Africa"
end if

if continent1 = Oceania then
put "You have selected Oceania"
end if

delay(850)
cls






put "Player2 pick your continent"

put "Pick beetween the following continents"

put "North America(1), South America(2), Europe(3), Asia(4), Africa(5), Oceania(6)"

put""

put"Do not pick the same continent as Player1 or the game will end!"

get continent2

if continent2 = continent1 then
put "You have failed to follow instruction"
end if

if continent2 = NorthAmerica then
put "You have selected NorthAmerica!"
end if

if continent2 = SouthAmerica then
put "You have seleceted South America"
end if

if continent2 = Europe then
put "You have selected Europe!"
end if

if continent2 = Asia then
put "You have selected Asia!"
end if

if continent2 = Africa then
put "You have selected Africa!"
end if

if continent2 = Oceania then
put "You have selected Oceania!"
end if

delay(850)
cls






put "Player 3 pick your continent"

put "pick beetween the following continents"


put "North America(1), South America(2), Europe(3), Asia(4), Africa(5), Oceania(6)"

put ""

put "Do not pick the same continent as Player 1/2 or the game will end!"

get continent3

if continent3 = continent1 then
put "You have failed to follow instruction"
end if

if continent3 = continent2 then
put "You have failed to follow instruction"
end if

if continent3 = NorthAmerica then
put "You have selected North America!"
end if

if continent3 = SouthAmerica then
put "You have selected South America!"
end if

if continent3 = Europe then
put "You have selected Europe!"
end if

if continent3 = Asia then
put "You have seleceted Asia!"
end if

if continent3 = Africa then
put "You have selected Africa!"
end if

if continent3 = Oceania then
put "You have selected Oceania!"
end if

delay(850)
cls






put "Player 4 pick your continent"

put "Pick beetween the following continents"

put "North America(1), South America(2), Europe(3), Asia(4), Africa(5), Oceania(6)"

put ""

put "Do not pick the same continent as Player(s)1/2/3 or the game will end"

get continent4

if continent4 = continent1 then
put "You have failed to follow instruction"
end if

if continent4 = continent2 then
put "You have failed to follow instruction"
end if

if continent4 = continent3 then
put "You have failed to follow instruction"
end if

if continent4 = NorthAmerica then
put "You have selected North America!"
end if

if continent4 = SouthAmerica then
put "You have selected South America!"
end if

if continent4 = Europe then
put "You have selected Europe!"
end if

if continent4 = Asia then
put "You have selected Asia!"
end if

if continent4 = Africa then
put "You have selected Africa!"
end if

if continent4 = Oceania then
put "You have selected Oceania!"
end if

delay (850)
cls






put "Player 1 would you like to attack(1), make an alliance(2), or pass(3)?"
get choice1

if choice1 = 1 then
put "Who would you like to attack?"
get p1choice2a
end if

if choice1 = 2 then
put "Who would you like to make an alliance with?"
get p1choice2all
end if

if choice1 = 3 then
put "You have passed your turn to Player 2"
end if

if p1choice2a = name2 then
put "You have declared war on " , continent2 , "!"
end if

if p1choice2a = name3 then
put "You have declared war on ", continent3, "!"
end if

if p1choice2a = name4 then
put "You have declared war on ", continent4 , "!"
end if

if p1choice2all = name2 then
put "You have offered ", continent2 , "an alliance.", continent2, "Do you accept(1), or decline(2)?"
get p2choice2all
end if

if p1choice2all = name3 then
put "You have offered ", continent3, "an alliance.", continent3, "Do you accept(1), or decline(2)?"
get p2choice2all
end if

if p1choice2all = name4 then
put "You have offered", continent4, "an alliance.", continent4, "Do you accept(1), or decline(2)?"
end if
Sponsor
Sponsor
Sponsor
sponsor
richcash




PostPosted: Sat Oct 07, 2006 1:17 pm   Post subject: (No subject)

I will discuss the error when you want to attack and press 1.
The problem is that you only get the variable p1choice2all if the person selects alliance. So, if they don't (they choose attack or pass), p1choice2all never gets a value. Then you go on to check if this variable is equal to name2, and the variable has no value. A quick solution would be to initialize all of the variables that might have no value (will only be supplied a value from the user under certain conditions) as "".
code:
p1choice2all := ""
%... and others that might have no value.

When you get further into programming, you can shorten this code greatly with arrays and for loops.
Also, you can use code tags when posting on this website. It makes it more readable.
Gilby101




PostPosted: Sat Oct 07, 2006 1:44 pm   Post subject: (No subject)

Thanks a lot, I am in Gr.10 and it's my first CPU Sciences course, so I am new to it, but I like it. I will keep in mind what you said about the code display. Thanks for the help too Smile .
[Gandalf]




PostPosted: Sat Oct 07, 2006 8:33 pm   Post subject: (No subject)

Welcome to the forums.

Just wanted to point out that you're not taking CPU Sciences, you are most probably taking Computer Science. CPU is a part of the computer.

Also, I would imagine it's quite difficult to create any kind of Risk-type game. I suggest that you try something simpler to learn with. At least that way you'll be able to have some more success with whatever you create.
Gilby101




PostPosted: Sat Oct 07, 2006 9:19 pm   Post subject: (No subject)

I know the CPU = processor, but I just like to use it for short from ComPUter, anyway, I have already done all that simple jazz, my teacher gives us challenges like, making a tree, house, and sun. Or making a calculator... I just started this because I was done the others, and I just don't want to stop and start new until I am done... Sounds silly, but it is a sad truth.
BenLi




PostPosted: Sun Oct 08, 2006 1:38 pm   Post subject: (No subject)

a pong game is a good game to try and tackle in the beginning. Don't mess around with the trig and angles though just do the vx := -vx stuff
[Gandalf]




PostPosted: Sun Oct 08, 2006 7:30 pm   Post subject: (No subject)

Arrr! It seems my original post didn't get through yesterday...

That's a weird short form for computer you have there, Gilby101.

Risk isn't something that you'll have a lot of success making at such an early stage, it's like everyone who wants to create an RPG as soon as they know how to use "put" and "get", it's ridiculous. I suggest you first learn some more 'advanced' stuff like functions and arrays before even thinking about creating a Risk-type game.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 7 Posts ]
Jump to:   


Style:  
Search: