• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

I need some help in converting obsolete functions to the new ones

Zuljaras

Member
So I decided to port my project to GMS2 from GMS 1.4.

Everything runs as expected and I did not have to do any changes except some type errors (no idea where those came from!)
.
HOWEVER I want to convert my old functions to the new ones and I do not want to use the compatibility scripts.

Here is a sample:

GML:
var p = application_get_position();
var px = p[0];
var py = p[1];
var pw = p[2] - p[0];
var ph = p[3] - p[1];

global.mx = ((mouse_x - __view_get( e__VW.XView, 0 )) / __view_get( e__VW.WView, 0 ) * pw + px - global.Xoffset) / surface_get_width(application_surface) * __view_get( e__VW.WView, 0 ) + __view_get( e__VW.XView, 0 );
global.my = ((mouse_y - __view_get( e__VW.YView, 0 )) / __view_get( e__VW.HView, 0 ) * ph + py - global.Yoffset) / surface_get_height(application_surface) * __view_get( e__VW.HView, 0 ) + __view_get( e__VW.YView, 0 );

I read the obsolete functions list and the new functions list but I did not find the equivalents of those.

Could anyone tell me how did you managed to get those things to work in your projects?

Is it even possible to get the exact same thing but in the new functions?!

Thanks in advance!
 

obscene

Member
view_xview and view_yview are still global variables (though you don't have to put global. in front of them.) They will always have values of 0 unless you replace them. So I just do this and then use them as I was used to...

view_xview=camera_get_view_x(view_camera[0]);
view_yview=camera_get_view_y(view_camera[0]);

Never tried but I would guess view_wview and view_hview are the same.

Then just do a search and replace to get rid of all that mess GM2 created.
 

Tornado

Member
Yes, it is possible. We did that long time ago when we switched to GMS2. Those compatibility scripts are just wrappers.
It took some days for me to get rid of all of them, as we have a big project. Those "view" things and instance_create with depth were the worse, you have to be very carefull with that.

Just look in the object tree in GMS under scripts. You'll find the folder "compatibility". There you will find all of them.
Start with small steps, take first the easiest wrappers to get into the routine. When you finish one, rename that compatibility script (better to rename than to delete immediatelly) so that it never gets called. Then test your app. Then take on the next script.
At the end when everything works, you can delete those unused renamed compatibility scripts or you can keep them for some time, just in case, until you are sure that your conversion worked perfectly.
 
Last edited:

Zuljaras

Member
view_xview and view_yview are still global variables (though you don't have to put global. in front of them.) They will always have values of 0 unless you replace them. So I just do this and then use them as I was used to...

view_xview=camera_get_view_x(view_camera[0]);
view_yview=camera_get_view_y(view_camera[0]);

Never tried but I would guess view_wview and view_hview are the same.

Then just do a search and replace to get rid of all that mess GM2 created.
Yes, it is possible. We did that long time ago when we switched to GMS2. Those compatibility scripts are just wrappers.
It took some days for me to get rid of all of them, as we have a big project. Those "view" things and instance_create with depth were the worse, you have to be very carefull with that.

Just look in the object tree in GMS under scripts. You'll find the folder "compatibility". There you will find all of them.
Start with small steps, take first the easiest wrappers to get into the routine. When you finish one, rename that compatibility script (better to rename than to delete immediatelly) so that it never gets called. Then test your app. Then take on the next script.
At the end when everything works, you can delete those unused renamed compatibility scripts or you can keep them for some time, just in case, until you are sure that your conversion worked perfectly.
Thank you both.

I just feel that is it very hard to know which of the NEW functions covers the old ones.

I looked for a guide of sorts but nothing is available.
 

Tornado

Member
BACKUP YOUR PROJECT BEFORE DOING THIS!!!

In the Object Tree in folder "Notes" you will find compatibility report file. Open it and you'll see every place where something was converted.
Like:
Code:
Converting GML script: ${project_dir}\scripts\scr_restartMultiplayerLevel\scr_restartMultiplayerLevel.gml
Converted builtin - line 5: view_hview[0] -> __view_get( e__VW.HView, 0 )
Converted description /// @description  scr_restartMultiplayerLevel()
Seeing that file you can see what amount of work is awaiting you.

So, view_hview[0] was replaced by __view_get( e__VW.HView, 0 ).

Ok, you go and open compatibility script "__view_get" and check in the switch statement where is the the parameter e__VW.HView:

Aha, it's here:
case e__VW.HView: var __cam = view_get_camera(__index); __res = camera_get_view_height(__cam); break;
OK, first camera is get with index (0 in this case) and then view height is get from the camera, but we can write this together as one statement:
camera_get_view_height(view_get_camera(0))

So, this means wherever you have
__view_get( e__VW.HView, 0 )
in your ENTIRE project you can replace it by
camera_get_view_height(view_get_camera(0))

Just press (SHIFT-CTRL-F) and replace it in the whole project.

I doubt that you have several views in your game but if yes, it is also no problem, then
for view 1 you replace
__view_get( e__VW.HView, 1 )
by
camera_get_view_height(view_get_camera(1))

And so on...
__view_get( e__VW.XView, 0 )
will be replaced by
camera_get_view_x(view_get_camera(0))

etc...
 
Last edited:
Top