Upgrading from Blitz plus, need pointers.

Monkey Forums/Monkey Beginners/Upgrading from Blitz plus, need pointers.

Jello Fox(Posted 2016) [#1]
Ok, I have more or less figured out some of the basic changes in the syntax and such, however I'm trying to figure out how to use class's to do what I used to do in blitz plus.. example..

I have a type named Platform named plat..

In Blitz plus I used this by declaring a new one,
plat.plat = new plat

and so on.

then looped through them when it was time to check them against the player,
for plat.plat=each plat

;check and update stuff..


also doing this,

for plat.plat=each plat
if plat\typ=1
for obj.obj=each obj

check if an obj collides with the platform.


I am totally lost on how to do this in Monkey. I get that the classes can have their own functions but how do I make a bunch of platforms and loop through them to check? I'm a bit lost ...ok I'm totally lost.

I need advice... Also if someone can explain how I'm supposed to set image masking that would be a big help. I'm trying to take a platforming engine I'm making and transfer it to monkey..

Gerry Quinn(Posted 2016) [#2]
Something like this will work:

As for image masking, not quite sure what you mean here - you can have images with transparent areas. If you mean collision masking, there's nothing built-in. though there is probably code out there.

Jello Fox(Posted 2016) [#3]
Hmmm.. so setting a list is how you track your types...so if I'm reading this right...

class plat

field x:int
field y:int
field image:int
field frame:int


that is how I set the class.. then,

Global list< plat > platforms = new list< plat >
1.the global declares that it cam be used through the entire program,
2.then the list identifies what type of class it is a list of,
3.then the name of the list "platforms" in this case
4. Then the command for a new list to be made with the class the list is to be made of

platforms.addlast( new plat() )
this acts as the code to create the new plat and add it to the list on the end...

and finally the

For local platforms:plat = each in platforms

is how I access my platforms? .. I think I get it now.. thank you!.

Oh, by image masking I meant that when I used blitz pro you could do this.

global playerimage=loadimage("player.bmp")
maskimage (playerimage,255,0,255)
where the command takes the handle of the image, then the red,green,blue color data and makes those pixels invisible.

so I can have a color other than black be invisible when the character is drawn. Does this remind you of anything you've seen in Monkey?

Pakz(Posted 2016) [#4]
Monkey has the alpha value for each pixel in an image. This way you can make an image completely or partly transparent. You might need to edit your images from blitzplus (the masked colored color) to have the correct alpha value so that it does not get drawn.

Jesse(Posted 2016) [#5]
you need to create a list variable. List and list are not the same. Monkey is case sensitive and List is the name of the "List" Class while "list" can mean anything:
Global platforms:List<plat>  ' declares platforms as a List of type "plat"
platforms = New List<plat> ' creates an instance of the List of type "plat"
Local itm:plat = new plat ' creates an instance of a plat type.
platforms.AddLast(itm)  ' saves the address of the itm instance in the platforms List.

to access objects in the List which name is platforms:
For Local item:plat = Eachin platforms ' access each of the plat in the platform List.
    item.x = 50

Gerry Quinn(Posted 2016) [#6]
By the way, a list is just one example of a collection class. You could use an array or a stack instead, or even other things.

Jesse(Posted 2016) [#7]
@Gerry, I think you are confusing him with this line:
Global List< Platform > plats = New List< Platform >()

Gerry Quinn(Posted 2016) [#8]
Oh right, I'm writing Java or C++ by mistake!

Global plats:List< Platform > = New List< Platform >

...is the Monkey syntax.

Jello Fox(Posted 2016) [#9]
I'm enjoying reading this, its helping allot guys. I'm stuck at this point tho.

I have a list and class set, the list is made, I've made a new object and now I want to effect its variables.. It says I cant access the variable from here.....

so ...? I need to be able to set some of the fields when I made the new object.. say I'm making a bullet, I need to tell it that it belongs to an object and where it begins its short but deadly life..(deadly if it hits the player. lol.)

Anything special I need to do when I make a new thing?

Local itm:plat = new plat ' creates an instance of a plat type.
platforms.AddLast(itm)' adds it to the list of plats

now how do I set its variables?

(I'm still trying to figure all this out really.. )

Jesse(Posted 2016) [#10]
to init the bullet:
Local itm:plat = new plat ' creates an instance of a plat type.
itm.x = 50
itm.y = 20
platforms.AddLast(itm)' adds it to the list of plats

to update:
For Local obj:plat = EechIn platforms
   obj.x = obj.x + 2 'adds 2 to plat x ' add 2 to the x instance of plat.
   If obj.x > 640 ' check to see if bullet exited the screen
        platforms.RemoveEach(obj) ' remove this instance of plat from the list.
Next ' get next plat instance

Jello Fox(Posted 2016) [#11]
Ok... I think I get it.. you use a local variable to make the obj.. then by adding it to the list its stored in the list and the local variable , well can it be reused?

so.. I think I have enough info here to start porting over my platforming engine from blitz to monkey... If I run into more problems I know where to post. Thanks everyone!!

Jello Fox(Posted 2016) [#12]
Just to be safe..
1. do thee first in the first steps of the program to set up the list for use later.\

Global platforms:List<plat> ' declares platforms as a List of type "plat"
platforms = New List<plat> ' creates an instance of the List of type "plat"

2.Then, later on in the main function or loop of the program use this to make new items or platforms or whatever it is named.
Local item:plat = new plat ' creates an instance of a plat type.

but my question is, if I want to make more of these when certain events happen like the player is in the target zone or say I'm doing a particle effect, can I use the same local variable over and over again? Or is there another proper way?

this was so simple in blitz plus..

type plat
field y
field x
field frame
field image
end type

plat.plat=new plat

and then to loop through them,

for plat.plat=each plat

do stuff.


Hopefully I understand it now.. ha.

Jesse(Posted 2016) [#13]
>if I want to make more of these when certain events happen like the player is in the target zone or say I'm doing a particle effect, can I use the same local variable over and over again?

understand that every time you create an instance of an object, the address of the instance is the only thing that is being stored in the variable. So when you store the object in the list what you are really doing is saving the address of that object for future use. you can create as many objects as you want and assign it to the same variable as long as you store the address of every object some where. in your case a "List".
the best way to learn is to try stuff. you won't have to wait until somebody answers your questions to find out if something works.
The biggest problem for you is going to be, I think, getting used to the monkey standard, specially since I am sure you are not used to program with restrictions. by restrictions I mean that you need to use the default Class, use the default methods, and be restricted to draw everything trough the OnRender Method of the Default class. Personally I think you should have started with BlitzMax. I am not saying Monkey is really hard. it's just that some people just don't get the concept Of OO programming and with the restrictions imposed by MonkeyX makes it more difficult for beginners. I hope you do. Once you get it you'll love it but until you do, you probably won't really like it.
If you try stuff and can't figure out how to do it right then post the code and someone here will help you figure it out. Don't try to run with out knowing how to walk. :)

I suggest you go throng as many of the tutorials examples by Pakz and try to understand them as you go. They will really help you out:

Gerry Quinn(Posted 2016) [#14]
I've never found the default App class and OnRender() methods etc. to be an issue. Aren't you going to make something almost identical anyway, if you start from scratch - at least if you are producing a graphic program like a game? And any framework will do the same.

[I suppose the only issue with App is that it is designed to be multi-target, so it may have some methods that wouldn't apply to your particular target, and maybe a few decisions that could be more elegant. But essentially, you are always in an update-render loop of some kind by virtue of the hardware and the user's expectation of feedback - and you can structure things how you want on top of that.]

Jesse(Posted 2016) [#15]
I am sure you didn't start on Monkey with out any knowledge of OO programming. I remember looking at C++ OO before moving to Blitzmax and couldn't figure what the heck was going on. It took me a while of trial and error testing before I started to get the hang of it. Anyway maybe it's not as complicated as I remember but I have notice some programmers that come straight from procedural programming and struggle with OO coding.

Jello Fox(Posted 2016) [#16]
I love to tinker with demos and pre-made games to figure out how the code works.. I took apart Galaxiga 2.0 which was one of the games packed with the old blitz.. I modified the game pretty heavily.. I learned allot about how to code just doing that.

I'm working on physics engines for 2d gaming , simple collisions and such, however the way I program almost requires that I can have the above situations work correctly.

I think I'm understanding allot of what is being said, i'm just getting used to the new syntax..

I plan to take an older design and mix it with my new physics and collision code to make a 2d engine that I can base all my projects off of.. The end goal is to make classic NES style games and if I get better at art, SNES style games. I had my engine, (The Turmultuous Tower Engine) as I call it, ready and almost itself a game.. However I decided to upgrade and update to Monkey X to be able to reach other systems.(I know Turmultuous is not a word, its a mix of Turmoil and Multiple..)

The old design I mentioned was for a game I was working on called Swapshot and it used an array level system where the array had 3 dimensions. X,Y, and Type. I used that array for physics and for the drawing/rendering. it was pretty good but I had problems with the player interacting with it. I believe I've solved those issues and I'm trying to build that in Monkey so it can be a cross platform game.Most of the code wont need any special changes when changing from flash to say html5 or any other.. controls and such will, but I'll get to that later.

My games will be fairly simple when it comes to graphics and I think I will be able to convert all my old code now that I'm getting the hang of it.

I will continue to post questions when I get stumped, however tinkering usually gives the best results in my experience..

Jello Fox(Posted 2016) [#17]
I can now safely say I understand what to do on that front..

However Multidimensional Arrays are now kicking my butt.. Going to check out some tutorials and get myself sorted.. Thanks for all the help!

Jello Fox(Posted 2016) [#18]
I've picked up allot and am now programming with Monkey x pretty well.. I'm still using blitz plus to test and figure out my code before porting it to monkey but my plat-former demo is coming along nicely!

Thank you all for the help and I hope top be posting demos soon.