blitz+ game wont run

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
Fart
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 6
Joined: Fri Apr 11, 2008 1:03 pm

blitz+ game wont run

Post by Fart »

cant figure out why this runs funny

Code: Select all

Graphics 400, 300

;Constants
Const STARTHITPOINTS = 3
Const SHIP$ = "<-*->"
Const ESCKEY = 1, SPACEBAR = 57, UPKEY = 200, LEFTKEY = 203, DOWNKEY = 208, RIGHTKEY = 205
Const STARTX = 200, STARTY = 150

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;TYPES
Type ship
	Field x,y ;location
	Field hitpoints ; ship's hit points
	Field directionx
	Field directiony
	Field shipstring$
End Type


Type badship
	Field x,y ;location
	Field hitpoints ; ship's hit points
	Field directionx
	Field directiony
	Field shipstring$
End Type

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

SeedRnd	MilliSecs()
For enemycounter = 0 To 99; ;100 new ships
	enemy.badship = New badship
	enemy\x = Rand(1, 640)
	enemy\y = Rand(1, 480)
	enemy\hitpoints = 3
	enemy\x = enemy\x + enemy\directionx
	enemy\y = enemy\y + enemy\directiony

	
Next


For enemyships.badship = Each badship
	If hitpoints <= 0
		Delete enemyships
	EndIf

Next

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;INITIALIZATION SECTION
Global cont = 1
Global player.ship = New ship
player\x = STARTX
player\y = STARTY
player\hitpoints = STARTHITPOINTS
player\shipstring = SHIP$
enemy\directionx = Rand(-3,3)
enemy\directiony = Rand(-3,3)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;draws the hud
Function DrawHUD()
	Text 260, 10, "X position: " + player\x
	Text 260, 20, "Y position: " + player\y
	Text 260, 30, "Hitpoints: " + player\hitpoints         
End Function

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;move the creature randdomly & feed
Function TestInput()
;if player presses left, move him left.
If KeyHit(LEFTKEY)

	player\x = player\x - 3
	If player\x <0>= 385
		player\x = 380
	EndIf
	
EndIf

;if player presses up, move him up.
If KeyHit(UPKEY)

	player\y = player\y - 3
	If player\y <0>= 285
		player\y = 280
	EndIf
	
EndIf

;if player presses spacebar, remove hit point
If KeyHit(SPACEBAR)
	player\hitpoints = player\hitpoints -1
	If player\hitpoints <=0
		cont = 0
	EndIf
EndIf

;if player presses Esc, set cont to 0, and exit the game
If KeyHit(ESCKEY)
	cont = 0
EndIf


End Function

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;Game loop
While cont = 1
	Cls
	Text player\x, player\y, player\shipstring$
	TestInput()
	DrawHUD()
	Flip()
Wend
;End of loop
User avatar
Arce
Jealous Self-Righteous Prick
Jealous Self-Righteous Prick
Posts: 2153
Joined: Mon Jul 10, 2006 9:29 pm

Post by Arce »

What do you mean by 'runs funny?'

What's it supposed to do? And what's it do?

Then I'll take a look at it. xD
<qpHalcy0n> decided to paint the office, now i'm high and my hands hurt
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Post by Falco Girgis »

...dude, c'mon.

Seriously, if we're going to take the time to debug your code (which we don't do), please give us enough info to do something.
User avatar
Arce
Jealous Self-Righteous Prick
Jealous Self-Righteous Prick
Posts: 2153
Joined: Mon Jul 10, 2006 9:29 pm

Post by Arce »

Listen...Not to be rude or anything, but I am not going to be able to help you in the future unless you give me a bit more to go on. Just posting a program and saying "fix it" isn't going to work. I need to know what the problem is, what the error is, etc.

In this case, I tried to compile the above code. I got an 'Object does not exist ' error from the following lines:

Code: Select all

	enemy\directionx = Rand(-3,3)
	enemy\directiony = Rand(-3,3)
Before I go into how to fix it, I'm going to explain a little about the syntax.

Judging by the way the program is written, I'm guessing you wrote parts of this program based on some kind of example you were given (and thus don't fully understand the syntax?)

You're probably wondering "why is it giving me this message when i created the objects in these lines:"

Code: Select all

For enemycounter = 0 To 99; ;100 new ships
   enemy.badship = New badship
   enemy\x = Rand(1, 640)
   enemy\y = Rand(1, 480)
   enemy\hitpoints = 3
   enemy\x = enemy\x + enemy\directionx
   enemy\y = enemy\y + enemy\directiony
Next
Yes, you DID just create 99 objects called 'enemy'. However, notice how they are enemy.badship? Why do you require a period in the syntax?

Badship is the type of object it is. You defined yours like so:

Code: Select all

Type badship
   Field x,y ;location
   Field hitpoints ; ship's hit points
   Field directionx
   Field directiony
   Field shipstring$
End Type
So, here you're creating a 'badship' with the above variables. However, you're 'naming' it enemy. This allows you to access those variables by calling it 'enemy'. In other words, whenever you refer to 'enemy' you're referring to a specific badship. When you do

Code: Select all

enemy\x = Rand(1, 640)
you are actually setting a specific Badship's x to a random value.

The thing is, you're calling all 99 objects the same thing. You're calling them all 'enemy'. So how does it know the difference between which one you're talking about? IT DOES'T.

Since it doesn't know 'which enemy' you're talking about, the next time you try to reference 'enemy' it has no idea which one to reference. (And, if you understand this concept, the real, internal issue here is that earlier when you declared 'enemy' it was declared in a loop as a local variable. When you exit that loop, the local addresser is no longer good, you need a new one.)

So pretty much these lines right here are what are crashing it:

Code: Select all

	enemy\directionx = Rand(-3,3)
	enemy\directiony = Rand(-3,3)
simply because you created 99 enemies and it has no way to tell what is what. So how do you fix that?

I'm assuming that you want to do this to ALL 99 enemies. You would accomplish this much in the same way as you create the 99 enemies: with a for loop. The corrected syntax looks like this:

Code: Select all

For enemy.badship = Each badship  
	enemy\directionx = Rand(-3,3)
	enemy\directiony = Rand(-3,3)
Next 
What this segment does is loop through every 'badship' object, temporarily name it 'enemy' for the sake of acessing, set the two directions, then continue with the loop and move onto the next object. That way, 'enemy' is now a valid identifier.

I hope that made sense. In the shortest way possible, change

Code: Select all

	enemy\directionx = Rand(-3,3)
	enemy\directiony = Rand(-3,3)
to

Code: Select all

For enemy.badship = Each badship  
	enemy\directionx = Rand(-3,3)
	enemy\directiony = Rand(-3,3)
Next 

Now it should compile. However, upon compiling it, I (think) you will find that there are a number of bugs that you may need to work out (as I'm sure that you didn't intend on the outcome I got). If you need help sorting these out, I wouldn't mind aiding in my free time.

However, THIS IS THE LAST TIME I AM GOING TO HELP YOU WITHOUT MORE SPECIFIC DETAILS OF THE PROBLEM. If you're going to ask for help, please tell me not only what's wrong, but where you think the problem may be...And finally please, PLEASE re-read your post to be sure it is readable and makes sense (this isn't directed at you, and I'm not intending on sounding rude...We just get tons of "omg fx teh bugzez plz plz plz @@!!!!11")

Thanks, and good luck!
<qpHalcy0n> decided to paint the office, now i'm high and my hands hurt
User avatar
Dr. House
Respected Programmer
Respected Programmer
Posts: 20
Joined: Tue Mar 18, 2008 7:54 am

Post by Dr. House »

Your question and wording (or lack thereof) are absolutely horrendous. Lucky for you, Arce happens to be a rather nice guy. Way too nice if you ask me.

Somebody who won't take the time to explain exactly what is wrong with his code is clearly not deserving of our time or energy.

If we're going to take the time to help you, then you should take the time to help us help you.
Everybody Lies.
Fart
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 6
Joined: Fri Apr 11, 2008 1:03 pm

Post by Fart »

forgive me guys, wont happen again, I will check out what Arce said and report back. Again, sorry and thanks for helping.

As far as "acting funny" The program, goes full screen black and then blitzcc.exe crashes and thats about it.
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Post by MarauderIIC »

Thanks for the concise reply and learning from your mistakes :)) Better than most
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
User avatar
eatcomics
ES Beta Backer
ES Beta Backer
Posts: 2528
Joined: Sat Mar 08, 2008 7:52 pm
Location: Illinois

Post by eatcomics »

Wow this topic looks very familiar and almost seems that those remarks were aimed at me :lol:
Image
Post Reply