types
BlitzMax Forums/BlitzMax Beginners Area/types
| ||
how can i use types to create a visible object in a window? |
| ||
like this ? not quite sure what you mean. you really need to read this tutorial http://www.blitzbasic.com/Community/posts.php?topic=42519 |
| ||
see what you get for this: |
| ||
sorry... stupid mistake. didnt make a new bullet before i manipulated it. |
| ||
never mind, still doesnt work! new code: |
| ||
Hallo, Me thinks you've still to grasp a thing or two about Max's OO usage ;-) Looking at your code snippet, you want to create a TBullet object using the playershoot() function. That's cool. Only what you want to do is return that new instance you create back somewhere... eg Function playershoot:TBullet(x:Int,y:Int) Local Bullet:TBullet = New TBullet TBullet.x = sx TBullet.y = sy Return Bullet EndFunction ...then you would call it using something along the lines of Local myBullet:TBullet = TBullet.playershoot( x, y) your myBullet variable would then contain a reference to a TBullet object which you can then processes in an update loop etc... Now, onto the update() "function". As it stands, you can't do what you have in the code. I would suggest you change it to a Method instead : Method update() x :+ 1 End Method This way you can call it in the following way : myBullet.update() If you really wanted to use a function and also wanted to reference a types' field using TBullet.x, you would have to change the Field to a Global. But then "x" would be global for all instances of a TBullet oject (that is, every TBullet object you had would have the same x value). There are some nice OO Max tutorials about which might help get your head around it. I'm sure someone has some links handy they could post? :-) |
| ||
drnmr, Seriously, take a look at that link I posted, in it is the best tutorial right now available, Beginners Guide to BMax, you need to read that. |
| ||
now i have a problem with max not recognizing the functions later in my code. |
| ||
have you gone through the Beginners Guide yet ? |
| ||
yep |
| ||
well please post code so people can help you |
| ||
[codebox] Type TBullet Field x:Int Field y:Int Function playershoot(x:Int,y:Int) Global Bullet:TBullet Bullet = New TBullet Bullet.x = sx Bullet.y = sy EndFunction Function draw() DrawImage imbullet, bullet.x,bullet.y EndFunction Function update() Bullet.x = +1 EndFunction [\codebox] |
| ||
If you put the function in the Type you must call it like TBullet.playershot(x,y) not playershot(x,y) |
| ||
i am. Type TBullet Field x:Int Field y:Int Function playershoot(x:Int,y:Int) Global Bullet:TBullet Bullet = New TBullet Bullet.x = sx Bullet.y = sy EndFunction Method draw()'doesnt recognise TBullet.draw() later on DrawImage imbullet, bullet.x,bullet.y EndMethod Method update() Bullet.x = +1 EndMethod |
| ||
You delcared it global within a function. I think dreamora thinks the whole thing is within a type because you didnt put a end type. And if that is the case you only use global stuff within type functions. And in that case the below should work But I should tell you now it looks like your going down the wrong direction. You should be looking at list, methods, etc. Editings: Heres what i would do... Tho that dose work I would suggest reading and understanding the tutorials that have been written about the subject of OOP design and BMax OOP. |
| ||
no offense, but almost nothing in this topic has helped so far. |