My Game
BlitzMax Forums/BlitzMax Beginners Area/My Game
| ||
Let me first say this, this is not going to be a completed game (yet :)) but will become one after I convert my game to SuperStrict and fix many syntax errors. This thread will be devoted to fixing every little snippet of non-SuperStrict code. I will post my issues here (hope I don't have any though) lol. |
| ||
First question! When you see an underscore followed by a variable, what does that mean? Function init:TBullet(_x:Float, _y:Float, _dx:Float,_dy:Float,_speed:Float) |
| ||
Nothing. It's just part of the name. People use all kinds of naming conventions to remind themselves of various things. For example, a variable name beginning with the underscore character might be used to remind someone that the variable concerned is private and should not be used. |
| ||
Ok, now second. I am trying to use SuperStrict. (Its a first go and I have trouble). The compiler says Identifier "masterC" not found I don't get that because I create an MasterChief (Type) and put the handle of masterC on it before I give masterC values (x and y) SuperStrict AppTitle="[Halo Action Game]: ZaChO" 'title of program Graphics 800,700 'screen is 800 pixels wide and 700 pixels [vertically] long SeedRnd MilliSecs() 'need this to make random numbers AutoMidHandle False 'computer doesn't grab image @ center of images Global ScreenCount:Int=0 ' Number of the current screenshot Global MaxScreenShot:Int=100 ' Maximum number of screenshots allowed Global font:TImageFont=LoadImageFont("C:\WINDOWS\Fonts\Chiller.ttf",24) SetImageFont(font) SetMaskColor(255,255,255) 'masks white Type TEntity Field x:Int Field y:Int Field frame:Int Field health:Int Field ammo:Int EndType Type MasterChief Extends TEntity 'Function create(_x:Int,_y:Int,_frame:Int) Function create() masterC:MasterChief = New MasterChief masterC_x = 34 masterC_y = 575 masterC_frame = 0 End Function Function draw() DrawImage haloImage, masterC_x, masterC_y EndIf End Function Function updatePos() ' 'RIGHT If KeyHit(KEY_RIGHT) Or KeyDown(KEY_RIGHT) masterC_x = masterC_x + Rand(6,9) EndIf ' 'LEFT If KeyHit(KEY_LEFT) Or KeyDown(KEY_LEFT) masterC_x = masterC_x - Rand(6,9) EndIf End Function End Type Type AquaTurtle Extends TEntity EndType Type SandMonster Extends TEntity EndType Type SeaSerpent Extends TEntity EndType ' S N I P E R B U L L E T Type TBullet Extends TEntity Field dx:Int Global bulletSlist:TList = New TList Function init:TBullet(_x:Int, _y:Int, _dx:Int) b:TBullet = New TBullet b.x = _x b.y = _y b.dx = 70 ListAddLast bulletSlist, b EndFunction Function draw() For Local b:Tbullet = EachIn bulletSlist DrawImage bulletSnipe, b.x, b.y, 0 Next EndFunction Function refresh() For b:TBullet = EachIn bulletSlist DrawImage bulletSnipe, b.x, b.y, 0 b.x :+ b.dx If b.x >= 800 ListRemove bulletSlist, b ; Continue Next EndFunction EndType ' 'IMAGES ' Global haloImage:TImage = LoadImage("myurl.bmp") While Not KeyDown(KEY_ESCAPE) Cls MasterChief.create() MasterChief.draw() MasterChief.updatePos() Flip Wend End |
| ||
Let the compiler help you! When you try to compile that, it points to the line the error is on. It's the first line, not the second or third. masterC:MasterChief = New MasterChief << error is here! masterC_x = 34 << not here! masterC_y = 575 << or here! You think you're declaring it with the first line but you're not. You need to give a variable scope to declare it. Thus: Local masterC:MasterChief = New MasterChief You have an EndIf without an If in your draw function and you have more variables undeclared, but I presume you haven't got to those yet, so I've just solved the problem you asked about. |
| ||
Just to help you understanding: You could split the creation of an object in two lines. local masterC:Masterchief masterC=new MasterChief In line 1 you define which kind of object masterC will be and if it's local or global. Superstrict forces you to define both. In line 2 the object is 'really' created and allocated in memory so you can access its fields and methods. |
| ||
Oh ok, Im not familiar with superstrict yet so thanks for clarifying that I needed either local or global. And about the endif statement, it was a typo (thanks for pointing it out :)) Thanks so much for helping me out with this error! |
| ||
Isn't it true once you create an instance of a type using New that the values for the type are also created? Identifier 'masterC_x' not found What gives? Code: |
| ||
You use a period (.) to specify fields of a type :masterC.x Much like in Java, C++, C#, etc... :-) |
| ||
Oh, ok. Thanks! |
| ||
Does anyone see anything wrong with my draw() function. The compiler says Identifier 'masterC' not found I would think its not finding the type of MasterChief with the handle of masterC but I call create (which makes the new instance of the type) before drawing it, so I don't get it... |
| ||
You define 'masterC' as a local in the function MasterChief.create(), thus the variable is knocked off the stack and lost forever once the function returns. |
| ||
You may find that using Methods instead of Functions in your Types will make things a bit easier for you. Currently, you are not really using Types in a OO sense... actually more like a procedural style. You may want to start with something a bit more simple - code wise - or at least build your code more slowly... compiling often. This way errors will appear as you develop, and you will be able to fix them one at a time. Rather than is the case currently, where you have so many errors in your code that you may find yourself running round in circles :-) |
| ||
This is a good place to start... step-by-step examples of various subjects... to ease you into the syntax, etc. Has a good section on Types, and methods, and functions... :-) |
| ||
This is why I don't like SuperStrict, there is too much stuff for me to adjust to and the fact my knowledge bank is @ 0.20 cents... |
| ||
This is why I don't like SuperStrict, there is too much stuff for me to adjust to and the fact my knowledge bank is @ 0.20 cents... I've said this before, but I obviously need to say it again. There is nothing at all going on with SuperStrict that wasn't going on without SuperStrict. The only difference is that SuperStrict helps you find your errors where before you had no idea where they were. The number of errors hasn't changed. |
| ||
I've said this before, but I obviously need to say it again. There is nothing at all going on with SuperStrict that wasn't going on without SuperStrict. The only difference is that SuperStrict helps you find your errors where before you had no idea where they were. The number of errors hasn't changed. I agree fully. SuperStrict can only help you. |
| ||
I know SuperStrict is going to help me, its just that I take a long time to learn and then apply information. This is my first program which I'm using functions in types, using "Extends", using lists, and calling functions in the game loop. I mean, I've read some guides on how to do this stuff but it isn't completing the puzzle. I still have questions why, (especially why) something works and how does it work. Where is this called, what is this field for, etc. I'm a kind of guy who likes to make progress and understand whats happening and knowing what I'm doing. Right now I only have one quality "a kind of guy who likes to make progress." :) |