• 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!

GameMaker Issues with View System Compatibility With Regards to HeartBeast's Turn-Based RPG Course

C

Caniss Altari

Guest
I'm taking HeartBeast's Turn-Based RPG course and I've been having a bit of trouble with converting it to GMS2 in regards to the new view system. Here are the compile errors I got:
Script: view_approach at line 14: unexpected symbol "=" in expression
Script: view_approach at line 14: malformed assignment Here's my code:
///view_approach(x, y, width, height, speed, zoom_speed)
var xx = argument0;
var yy = argument1;
var width = argument2
var height = argument3
var spd = argument4
var zoom_spd = argument5

//Move towards the target
x = lerp(x, xx, spd);
y = lerp(y, yy, spd);

//Scale the view
camera_get_view_width(view_camera[0]) = lerp(camera_get_view_width(view_camera[0]), width, zoom_spd);
camera_get_view_height(view_camera[0]) = lerp(camera_get_view_height(view_camera[0]), height, zoom_spd);
And the code that the course was using is:
///view_approach(x, y, width, height, speed, zoom_speed)
var xx = argument0;
var yy = argument1;
var width = argument2
var height = argument3
var spd = argument4
var zoom_spd = argument5

//Move towards the target
x = lerp(x, xx, spd);
y = lerp(y, yy, spd);

//Scale the view
view_wview[0] = lerp(view_wview[0], width, zoom_spd);
view_hview[0] = lerp(view_hview[0], height, zoom_spd);
 
C

Caniss Altari

Guest
What is your thought process about this line?
I was trying to get the width of the viewport so I could use it in the lerp function and I searched up a replacement for the view_wview function.

Sorry if this sounds amateur-ish, I'm still kinda new to coding.
 
C

Caniss Altari

Guest
Thanks, I swapped out the code I had with this and it dealt with the compile errors:

///view_approach(x, y, width, height, speed, zoom_speed)
var xx = argument0;
var yy = argument1;
var width = argument2
var height = argument3
var spd = argument4
var zoom_spd = argument5

//Move towards the target
x = lerp(x, xx, spd);
y = lerp(y, yy, spd);

//Scale the view
camera_set_view_size(view_camera[0], width, height);

The only issue now is that I'm not sure how to make it zoom in smoothly with what I got now. If I'm not wrong, it'll move towards the target smoothly but then zoom in instantly.
 

chamaeleon

Member
I was trying to get the width of the viewport so I could use it in the lerp function and I searched up a replacement for the view_wview function.

Sorry if this sounds amateur-ish, I'm still kinda new to coding.
I asked to make you think about what the meaning would be, disregarding what any of the functions do specifically (except keeping in mind that you get a real back from camera_get_view_width()). You were essentially trying to assign some value to another value, hence the unexpected "=". GMS was trying to tell you that you couldn't assign the value of some expression to a real (in contrast to assigning the value of an expression to a variable). Therefore, you should take a step back and figure out what are trying to achieve, and break it down in manageable parts.

The only issue now is that I'm not sure how to make it zoom in smoothly with what I got now. If I'm not wrong, it'll move towards the target smoothly but then zoom in instantly.
You have removed any code relating to lerp() for the view size in your updated code (whether you could use that as is, is another matter).
 
C

Caniss Altari

Guest
I asked to make you think about what the meaning would be, disregarding what any of the functions do specifically (except keeping in mind that you get a real back from camera_get_view_width()). You were essentially trying to assign some value to another value, hence the unexpected "=". GMS was trying to tell you that you couldn't assign the value of some expression to a real (in contrast to assigning the value of an expression to a variable). Therefore, you should take a step back and figure out what are trying to achieve, and break it down in manageable parts.


You have removed any code relating to lerp() for the view size in your updated code (whether you could use that as is, is another matter).
Thanks for the help so far! I knew why my view wouldn't zoom smoothly, I'm just not sure how I could apply it to the code I have now. I'll update the post once I figure it out.
 
C

Caniss Altari

Guest
Alright, here's the code I got now:
///view_approach(x, y, width, height, speed, zoom_speed)
var xx = argument0;
var yy = argument1;
var width = argument2
var height = argument3
var spd = argument4
var zoom_spd = argument5
var old_width = camera_get_view_width(view_camera[0])
var old_height = camera_get_view_height(view_camera[0])
//Move towards the target
x = lerp(x, xx, spd);
y = lerp(y, yy, spd);

//Scale the view

camera_set_view_size(view_camera[0], (lerp(old_width, width, zoom_spd)), (lerp(old_height, height, zoom_spd)));

Think it might work?
 

chamaeleon

Member
Alright, here's the code I got now:
///view_approach(x, y, width, height, speed, zoom_speed)
var xx = argument0;
var yy = argument1;
var width = argument2
var height = argument3
var spd = argument4
var zoom_spd = argument5
var old_width = camera_get_view_width(view_camera[0])
var old_height = camera_get_view_height(view_camera[0])
//Move towards the target
x = lerp(x, xx, spd);
y = lerp(y, yy, spd);

//Scale the view

camera_set_view_size(view_camera[0], (lerp(old_width, width, zoom_spd)), (lerp(old_height, height, zoom_spd)));

Think it might work?
Only one way to find out.. :) If it works, I guess another question you'd need to answer if whether you want to a constant move and zoom change or you want both of them to slow down as you get closer. Right now you're lerping between position and size that is the case for the current frame. Which means as the difference get smaller the change lerp applies to get from the current value to the target value becomes a smaller change. If you want constant change, you'd want to record the starting position and size before starting to apply this script, and use those values as the first argument to lerp() instead of the current values for position and size, and change the zoom_spd from 0 to 1 over the range of steps/time you want it to take to finish the transition.
 
Top