RPG Game - Varriable has no value 
	 
	
		| Author | 
		Message | 
	 
		 
		Degensquared
 
 
 
    
		 | 
		
		
			
				  Posted: Tue Sep 11, 2007 2:25 pm    Post subject: RPG Game - Varriable has no value  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				I am trying to write a game after my first week of turing lessons, and I keep getting the error "variable has no value" although I am sure that I have set those values. This might be the order of my proccess, I have found out how to make a temporary fix by declaring them in the input step, but this just resets the round # to zero and player health to full, which is inconvenient.. I would like some help please XD
 
 
	  | Turing: | 	 		  
var roundnumber  : int
var gamestatus  : int
var playerhealth  : int
var playerdamage  : int 
var playermana  : int
var playeraction  : int
var playerburn  : int
var enemyhealth  : int
var enemymana  : int
var enemyaction  : int
var enemyburn  : int
var enemydamage  : int
var burndamage  : int
var start  : string
var airand : int
roundnumber  := 0
colorback(black)
color(white)
cls
proc setup
 setscreen("graphics:800;600")
roundnumber  := 1
gamestatus:= 0
playerhealth  := 250
enemyhealth  := 250
playermana  := 100
enemymana  := 100
playerburn  := 0
enemyburn  := 0
playeraction  := 0
enemyaction  := 0
burndamage  := 0
start  := "p"
colorback(black)
color(white)
cls
end setup
 proc input
 var playerhealth  : int
var roundnumber  : int
var playermana  : int
var playeraction  : int
put "Round - ", roundnumber
 put "Status: ", playerhealth,  "/250 HP | ", playermana,  "/100 MP"
put ""
put "What action would you like to take?"
put "1. Sword Attack (10-15 Damage)"
put "2. Lightning Magic (25-35 Damage, 10 Mana)"
put "3. Fireball Magic (20-30 Damage, 25 Mana, Causes Burning For 3 Rounds)"
put "4. Healing Magic (40-75 Healing, 20 Mana)"
put "5. Rest (10-20 Healing, Regain 20-30 Mana)"
put "6. Lay down your sword (Forfit the Game)"
get playeraction
 end input
 proc playersword
 
playerdamage  := Rand.Int  (10,  15)
enemyhealth  := enemyhealth - playerdamage
 put "You swing your sword at the enemy for ", playerdamage,  ", leaving your enemy with ", enemyhealth,  "/250 HP."
playerdamage  := 0
if (enemyhealth <  1) then
gamestatus  := 1
end if
end playersword
 proc enemysword
 
enemydamage  := Rand.Int  (10,  15)
playerhealth  := playerhealth - enemydamage
 put "The enemy swings it's sword at you for ", enemydamage,  ", leaving you ", playerhealth,  "/250 HP."
enemydamage: = 0
if (playerhealth <  1) then
gamestatus  := 2
end if
end enemysword
 proc playerlightning
 
playerdamage  := Rand.Int  (25,  35)
enemyhealth  := enemyhealth - playerdamage
 
playermana  := playermana -  10
put "Lightning strikes the enemy for ", playerdamage,  ", leaving your enemy with ", enemyhealth,  "/250 HP."
put "You are drained of 10 mana, leaving you with ", playermana,  "/100 MP."
if (enemyhealth <  1) then
gamestatus  := 1
end if
end playerlightning
 proc enemylightning
 
enemydamage  := Rand.Int  (25,  35)
playerhealth  := playerhealth - enemydamage
 
enemymana  := enemymana -  10
put "Lightning strikes you for ", enemydamage,  ", leaving you with ", playerhealth,  "/250 HP."
put "Your enemy is drained of 10 mana, leaving it with ", enemymana,  "/100 MP."
if (playerhealth <  1) then
gamestatus  := 2
end if
end enemylightning
 proc playerfireball
 
playerdamage  := Rand.Int  (20,  30)
enemyhealth  := enemyhealth - playerdamage
 
playermana  := playermana -  25
enemyburn  := 3
put "A fireball hits the enemy for ", playerdamage,  ", leaving your enemy with ", enemyhealth,  "/250 HP."
put "You are drained of 25 mana, leaving you with ", playermana,  "/100 MP."
put "The enemy will continue to burn for the next three rounds"
if (enemyhealth <  1) then
gamestatus  := 1
end if
end playerfireball
 proc playerburnproc
 if (playerburn <  0) then
playerburn  := playerburn -  1
burndamage  := Rand.Int  (5,  10)
playerhealth  := playerhealth - burndamage
 put "You have been burned for ", burndamage,  ", leaving you with ", playerhealth,  "/250 HP."
if (playerburn <  0) then
put "You will continue to burn for ", playerburn,  " rounds."
else
put "The flames on your body have extinguished!" 
end if 
end if
end playerburnproc
 
 proc enemyfireball
 
enemydamage  := Rand.Int  (20,  30)
playerhealth  := playerhealth - enemydamage
 
enemymana  := enemymana -  25
playerburn  := 3
put "A fireball hits you for ", enemydamage,  ", leaving you with ", playerhealth,  "/250 HP."
put "Your enemy is drained of 25 mana, leaving it with ", enemymana,  "/100 MP."
put "You will continue to burn for the next three rounds"
if (playerhealth <  1) then
gamestatus  := 2
end if
end enemyfireball
 proc enemyburnproc
 if (enemyburn <  0) then
enemyburn  := enemyburn -  1
burndamage  := Rand.Int  (5,  10)
enemyhealth  := enemyhealth - burndamage
 put "The enemy has been burned for ", burndamage,  ", leaving your enemy with ", enemyhealth,  "/250 HP."
if (enemyburn <  0) then
put "Your enemy will continue to burn for ", enemyburn,  " rounds."
else
put "The flames on your enemy's body have extinguished!" 
end if 
end if
end enemyburnproc
 proc playerheal
 
playerdamage  := Rand.Int  (40,  70)
playerhealth  := playerhealth + playerdamage
 if (playerhealth >  250) then
playerhealth  := 250
end if
playermana  := playermana -  20
put "A wave of magic passes over you, healing you for ", playerdamage,  ", leaving you with ", playerhealth,  "/250 HP."
put "You are drained of 20 mana, leaving you with ", playermana,  "/100 MP."
end playerheal
 proc enemyheal
 
enemydamage  := Rand.Int  (40,  70)
enemyhealth  := enemyhealth + enemydamage
 if (enemyhealth >  250) then
enemyhealth  := 250
end if
enemymana  := enemymana -  20
put "A wave of magic passes over your enemy, healing it for ", enemydamage,  ", leaving it with ", enemyhealth,  "/250 HP."
put "Your enemy is drained of 20 mana, leaving it with ", enemymana,  "/100 MP."
end enemyheal
 proc playerrest
 
playerdamage  := Rand.Int  (10,  20)
playerhealth  := playerhealth + playerdamage
 if (playerhealth >  250) then
playerhealth  := 250
end if
put "As you sit and meditate you feel your health slowly returning for ", playerdamage,  ", leaving you with ", playerhealth, "/250 HP."
playerdamage  := Rand.Int  (1, 3)
if (playerdamage  = 1) then
playerdamage  := 20
put "Your mana likewise returns to you for ", playerdamage,  ", leaving you with ", playerhealth, "/250 HP."
else if (playerdamage  = 1) then
playerdamage  := 25
put "Your mana likewise returns to you for ", playerdamage,  ", leaving you with ", playerhealth, "/250 HP."
else
playerdamage  := 30
put "Your mana likewise returns to you for ", playerdamage,  ", leaving you with ", playerhealth, "/250 HP."
end if
end if
end playerrest
 proc enemyrest
 
enemydamage  := Rand.Int  (10,  20)
enemyhealth  := enemyhealth + enemydamage
 if (enemyhealth >  250) then
enemyhealth  := 250
end if
put "As you sit and meditate you feel your health slowly returning for ", enemydamage,  ", leaving you with ", enemyhealth, "/250 HP."
enemydamage  := Rand.Int  (1, 3)
if (enemydamage  = 1) then
enemydamage  := 20
put "Your mana likewise returns to you for ", enemydamage,  ", leaving you with ", enemyhealth, "/250 HP."
else if (enemydamage  = 1) then
enemydamage  := 25
put "Your mana likewise returns to you for ", enemydamage,  ", leaving you with ", enemyhealth, "/250 HP."
else
enemydamage  := 30
put "Your mana likewise returns to you for ", enemydamage,  ", leaving you with ", enemyhealth, "/250 HP."
end if
end if
end enemyrest
 proc playerforfit
 
gamestatus  := 3
end playerforfit
 proc aiheal
 var enemymana : int
if (enemymana >=  20) then
enemyheal
 else
enemyrest
 end if
end aiheal
 proc airest
 
enemyrest
 end airest
 proc aifight
 
airand  := Rand.Int  (1, 3)
if (airand  = 1) then
if (playerburn  = 0) then
if (enemymana >=  25)then
enemyfireball
 else
airest
 end if
else
enemysword
 end if
else if (airand  = 2) then
if (enemymana >=  10) then
enemylightning
 else
airest
 end if
else
enemysword
 end if
end if
end aifight
 proc enemyai
 if (enemyhealth >=  190) then
if (enemymana >=  75) then
aifight
 else if (enemymana >=  50 and enemymana <  75) then
airand  := Rand.Int  (1, 2)
if (airand  = 1) then
aifight
 else
airest
 end if
else if (enemymana >=  25 and enemymana <  50) then
airand  := Rand.Int  (1, 4)
if (airand  = 1) then
aifight
 else
airest
 end if
else if (enemymana <  25) then
end if
end if
end if
end if
end if
end enemyai
 proc playerrun
 if (playeraction  = 1) then
playersword
 else if (playeraction  = 2) then
playerlightning
 else if (playeraction  = 3) then
playerfireball
 else if (playeraction  = 4) then
playerheal
 else if (playeraction  = 5) then
playerrest
 else if (playeraction  = 6) then
playerforfit
 end if
end if
end if
end if
end if
end if
end playerrun
 proc gamestart
 for colorloop  : 1 ..  2
locate(6,  42)
color(colorloop )
put "RPG GAME V.01"
put "By: Cody Veal"
delay(50)
cls
end for
color(white)
delay(1000)
cls
put "Would you like to start new game? (y/n)" ..
 get start
 end gamestart
 proc game
 loop
roundnumber  := roundnumber +  1
if (roundnumber  = 1) then
setup
 end if
input
 
enemyai
 
playerburnproc
 
playerrun
 
enemyburnproc
 exit when gamestatus <  0
end loop
end game
 proc flash  (flashtext  : string)
loop
for flashcolor  : 20 ..  255
cls
locate(18, 42)
color(flashcolor )
put flashtext
 end for
end loop
end flash
 proc gamefinish
 if (gamestatus  = 1) then
flash  ("YOU WIN!")
else if (gamestatus  = 2) then
color(red)
locate(18, 40)
put "You have been defeated..."
else
color(red)
locate(18, 40)
put "You lay down your sword in sumbmission to the enemy..."
end if
end if
end gamefinish
 proc main
 
gamestart
 
game
 
gamefinish
 end main
 
main
   | 	 
  | 
			 
			
				 | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
		 
		Sponsor Sponsor 
		 
  
		 | 
		
 | 
	 
	 
		  | 
	 
				 
		MichaelM
 
  
 
    
		 | 
		
		
			
				  Posted: Tue Sep 11, 2007 2:58 pm    Post subject: Re: RPG Game - Varriable has no value  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				I found youre problem. I noticed that your variables roundnumber, playerhealth, playermana and playeraction are declared both at the beginning of your program, and in your input proc. Inside the proc they are created as local variables, which at that point have no value. You also have global variables with the same names (which you declared at the start of your program), however your proc is using the local variables, such as roundnum, which has no value currently. It looks to me like these declarations in your proc are unnecessary and are what cause the problem. 
 
 
Just to test it out, I commented out variables roundnumber, playerhealth, playermana and playeraction from your input proc, and then it runs fine. A pretty cool game if i may add, however if you keep playing it you'll notice that as the screen scrolls down the background is no longer white. Good Luck, I hope that helps. | 
			 
			
				 | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
				 
		rdrake
 
  
 
    
		 | 
		
		
			
				  Posted: Tue Sep 11, 2007 3:30 pm    Post subject: RE:RPG Game - Varriable has no value  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				| Oh my...  Might I recommend creating a class to represent the player?  This should get you started. | 
			 
			
				 | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
				 
		CodeMonkey2000
 
 
 
    
		 | 
		
		
			
				  Posted: Tue Sep 11, 2007 3:57 pm    Post subject: RE:RPG Game - Varriable has no value  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				| Silly grade 10 classes, they teach you to make silly games, rather than teaching proper programming techniques. | 
			 
			
				 | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
				 
		Degensquared
 
 
 
    
		 | 
		
		
			
				  Posted: Tue Sep 11, 2007 6:24 pm    Post subject: RE:RPG Game - Varriable has no value  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				Tyvm! I hope this solves it (I was unsure whether turing differentiated between local and global XD)
 
I just need to wait until I can test this out at school tomrrow (darn holtsoft and their pricey compiler!) | 
			 
			
				 | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
				 
		Tony
 
  
 
    
		 | 
		
		
			
				  Posted: Tue Sep 11, 2007 6:44 pm    Post subject: Re: RE:RPG Game - Varriable has no value  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				Degensquared @ Tue Sep 11, 2007 6:24 pm wrote: I just need to wait until I can test this out at school tomrrow (darn holtsoft and their pricey compiler!) 
 
OpenT should be able to compile Turing programs soon.. ish. Stay tuned! Or better yet, find out how you can contribute to the project. | 
			 
			
				 
Tony's programming blog. DWITE - a programming contest. | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
				 
		Nick
 
  
 
    
		 | 
		
		
			
				  Posted: Tue Sep 11, 2007 6:47 pm    Post subject: RE:RPG Game - Varriable has no value  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				| hey i've been seeing a lot of turing problems ever since school has started and thats why i worte this a bit back (like a month or so iunno... not important) its a guide to help ur program... debugging as its called... here is the link | 
			 
			
				 | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
				 
		Degensquared
 
 
 
    
		 | 
		
		
			
				  Posted: Tue Sep 11, 2007 7:37 pm    Post subject: Re: RE:RPG Game - Varriable has no value  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				Tony @ Tue Sep 11, 2007 6:44 pm wrote: 
OpenT should be able to compile Turing programs soon.. ish. Stay tuned! Or better yet, find out how you can contribute to the project.  
 
I'd love to help out if I knew anything more than basic programming XD, If there are any other jobs that didn't require me to understand a heck of a lot of programming, I'll help out in a heart beat(I think it's being written in java right?). I'm reading up on classes, as we speak, hoping to learn how to incorporate that into my game for when I can start tomorrow. | 
			 
			
				 | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
		 
		Sponsor Sponsor 
		 
  
		 | 
		
 | 
	 
	 
		  | 
	 
				 
		Tony
 
  
 
    
		 | 
		
		
			
				  Posted: Tue Sep 11, 2007 8:16 pm    Post subject: Re: RE:RPG Game - Varriable has no value  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				Degensquared @ Tue Sep 11, 2007 7:37 pm wrote: I'd love to help out if I knew anything more than basic programming 
 
There's more to it than just programming. There's testing and documentation and a load of other things to do.
 
 
For example, right now we are looking for a new logo design.
 
 
Or simply increasing the awareness and finding more people who would be interested in the project would help as well. | 
			 
			
				 
Tony's programming blog. DWITE - a programming contest. | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
				 
		Nick
 
  
 
    
		 | 
		
		
			
				  Posted: Tue Sep 11, 2007 8:19 pm    Post subject: RE:RPG Game - Varriable has no value  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				i didnt know u needed help testing.. id be glad to help   | 
			 
			
				 | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
				 
		Degensquared
 
 
 
    
		 | 
		
		
			
				  Posted: Tue Sep 11, 2007 8:34 pm    Post subject: Re: RPG Game - Varriable has no value  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				Hey I'd love to try my hand at a logo, XD I'm pretty handy with that there Photoshop  .
 
 
Testing would also be an option   | 
			 
			
				 | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
				 
		Tony
 
  
 
    
		 | 
		
		
			
				  Posted: Tue Sep 11, 2007 8:59 pm    Post subject: RE:RPG Game - Varriable has no value  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				Well here's the OpenT logo contest thread. At the very least, make a post about your interest in the subject - they might extend the date.
 
 
Talk to rizzix and rdrake about what you could do to contribute. | 
			 
			
				 
Tony's programming blog. DWITE - a programming contest. | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
				 
		d2bb
 
 
 
    
		 | 
		
		
			
				  Posted: Thu Sep 13, 2007 4:50 pm    Post subject: Re: RE:RPG Game - Varriable has no value  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				CodeMonkey2000 @ Tue Sep 11, 2007 3:57 pm wrote: Silly grade 10 classes, they teach you to make silly games, rather than teaching proper programming techniques. 
 
 
 
lol. i used to be like that. little more practice and 100% better. | 
			 
			
				 | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
				 
		 | 
	 
 
	
	
	 
	
	 |