types

BlitzMax Forums/BlitzMax Beginners Area/types

drnmr(Posted 2006) [#1]
how can i use types to create a visible object in a window?


SillyPutty(Posted 2006) [#2]
like this ? not quite sure what you mean.



you really need to read this tutorial
http://www.blitzbasic.com/Community/posts.php?topic=42519


drnmr(Posted 2006) [#3]
see what you get for this:



drnmr(Posted 2006) [#4]
sorry... stupid mistake. didnt make a new bullet before i manipulated it.


drnmr(Posted 2006) [#5]
never mind, still doesnt work!
new code:



Brucey(Posted 2006) [#6]
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? :-)


SillyPutty(Posted 2006) [#7]
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.


drnmr(Posted 2006) [#8]
now i have a problem with max not recognizing the functions later in my code.


SillyPutty(Posted 2006) [#9]
have you gone through the Beginners Guide yet ?


drnmr(Posted 2006) [#10]
yep


SillyPutty(Posted 2006) [#11]
well please post code so people can help you


drnmr(Posted 2006) [#12]
[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]


Dreamora(Posted 2006) [#13]
If you put the function in the Type you must call it like

TBullet.playershot(x,y)

not playershot(x,y)


drnmr(Posted 2006) [#14]
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


Diablo(Posted 2006) [#15]


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.


drnmr(Posted 2006) [#16]
no offense, but almost nothing in this topic has helped so far.