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

GML Misunderstanding or bug with camera update script?

hippyman

Member
I haven't really messed with with cameras a ton but I may have come across a bug with camera_set_view_pos inside the camera update script.

Code:
view_enabled = true;
viewIndex = 0;
viewWidth = room_width;
viewHeight = room_height;
view_set_visible(viewIndex,true);
view_set_wport(viewIndex,viewWidth);
view_set_hport(viewIndex,viewHeight);

cameraID = camera_create_view(0,0,viewWidth,viewHeight,0,noone,-1,-1,-1,-1);
view_set_camera(viewIndex,cameraID);
camera_set_update_script(cameraID,camera_update);

Code:
var vcam = view_get_camera(view_current);
var vx = camera_get_view_x(vcam)
var vy = camera_get_view_y(vcam)
var axisX = key_to_axis(ord("D"),ord("A"));
var axisY = key_to_axis(ord("S"),ord("W"));
var spd = axisX != 0 || axisY != 0 ? 5 : 0;
var dir = point_direction(0,0,axisX,axisY);
vx += lengthdir_x(spd,dir);
vy += lengthdir_y(spd,dir);
camera_set_view_pos(vcam,vx,vy);
show_debug_message("Cam " + string(view_current) + " Update::"+string(dir)+"::"+string(vx)+","+string(vy));

I've tested this and the debug message shows that the camera view position is updating. But the view itself doesn't actually move. When I comment out the camera_set_update_script line and just place the camera_update code into the step event, everything works as expected. Is there something I'm misunderstanding about the camera update script or is this a bug that I should report?


EDIT: Starting to think I wasn't clear enough. Basically the "bug" I think I found is the function camera_set_view_pos doesn't seem to work properly when used inside a camera update script.
 
Last edited:

trg601

Member
Hmm... I haven't really messed with the new camera system much yet, but I would make sure that the camera you are updating is the same.
Try showing the value of vcam in the debug message instead of view current and see if that changes while using the script instead of the step event.
 

hippyman

Member
I'm positive that it's updating the correct camera. That was the purpose of checking view_current in the debug message.

The position variables are updated.

I also tested out changing the starting position of the camera and it changes the view position and has the correct position showing in the debug message and on the screen.

But when I start to move the camera view around with the keyboard, the position variables change but the view never actually moves on the screen.
 

trg601

Member
I just tried using the update script in my project and noticed the same problem. I guess this is a bug then.

I noticed that the begin and end scripts do work though, so maybe in the meantime you can use those.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Where are you calling the update script? If it's not in the draw event then it won't work as view_current is only valid in that event. If you want to use it elsewhere, use view_camera[viewIndex]. I can assure you the camera functions DO work correctly, and I've never had an issue with them...
 

hippyman

Member
Where are you calling the update script? If it's not in the draw event then it won't work as view_current is only valid in that event. If you want to use it elsewhere, use view_camera[viewIndex]. I can assure you the camera functions DO work correctly, and I've never had an issue with them...
I'm setting up the camera and using camera_set_update_script to assign the camera_update script that I put in the original post. I've tried this in the create event and the room event with the same results.

Just because you've never had issues doesn't mean that nothing is wrong. Something is definitely not right here. Although you are correct about my misuse of view_current. But even when I'm using a globally stored camera ID or just hard coding the index, camera_set_view_pos doesn't update the screen when called from a camera update script. It works fine when just calling it from the step event.

It's possible I'm just not explaining my issue well enough.

Here is a small example project that shows the exact issue I'm talking about.

https://www.dropbox.com/s/5rujpo0pq4ejgk1/cameraupdatescriptbug_ide2.1.4.288_rt2.1.4.212.yyz?dl=0
 
Last edited:

Nocturne

Friendly Tyrant
Forum Staff
Admin
Just because you've never had issues doesn't mean that nothing is wrong
Sorry, wasn't trying to come across as arrogant or anything! It's just that I used the camera system extensively when I was documenting it and I am currently working on a split screen 4 player game, and so I have 4 different cameras all working fine and being updated as is required. So it seems odd that such a seemingly simple thing doesn't work because of a bug and not because of user error. No offense intended, and you are quite correct that it could certainly be a bug! I'll check out the file you supply and report back... :)
 

hippyman

Member
No worries! I'm pretty sure this is because of my less than great ability to convey issues through dialog. lol (Not even sure if that last sentence makes sense)
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Hmmm... Okay, so, if you call the script using cmera_set_begin_script then it works exactly as required. However, if you do it using the update function it does not. I'm not entirely sure why, but I'll ask the devs on Monday at work about it. I'm not 100% sure it's a bug though. I suspect it's something I may have misunderstood when documenting the function. If it IS a bug I'll file it as one, but for now using the begin function will do exactly what you want. Thanks for bringing this to my attention, and I'm sorry for having doubted you! :)
 

hippyman

Member
Glad to help! I'm still pretty unfamiliar with the new camera system so I definitely thought there was a chance I was misunderstanding something otherwise I would have reported it myself. Thanks for taking a look and I'll be sure to use the begin update for now. Thanks for taking over. It does make life just a little bit easier not having to type up a bug report.
 
Top