Studio adds types of its own to GML for 3D and game code: vectors, rotations, transforms, colours, rectangles, boxes, dictionaries and sets. They are values with real operators, and the editor knows them: their names are coloured as types, completion lists their fields and methods after a ., the hover card shows each one's type and signature, and Problems warns about a misspelt field or the wrong number of arguments.
var pos = vec3(10, 0, 4);
var vel = vec3(1, 0, 0) * 120;
pos += vel * dt;
if (pos.distance_to(target) < 32) { ... }
var flat = pos.xy; // a vec2
var turned = quat_from_euler(0, 0, 90) * vec3_forward;
var c = colour_hex("#ff8800").with_alpha(0.5);
- Vectors:
vec2(x, y),vec3(x, y, z)(orvec3(v2, z)),vec4(x, y, z, w),vec3_splat(n), andvec3_zero,vec3_one,vec3_up,vec3_forward,vec3_right. Fields.x .y .z .wand swizzles (.xy,.zyx). Methods:length(),normalized(),dot(w),cross(w),distance_to(w),direction_to(w),lerp(w, t),move_toward(w, step),clamped(max),reflect(n),rotated(...)and more.+ - * /work with vectors and numbers. - Rotations:
quat_from_euler(x, y, z)(degrees),quat_from_axis(axis, deg),quat_look_at(dir, up),quat_between(a, b),quat_identity.q * vturns a vector,q * qcombines rotations;slerp(q, t),inverse(),to_euler(). - Transforms and matrices:
transform(pos, rot, scale)with.pos,.rot,.scale;mat4(...),mat4_build(...),mat4_identity. - Colours:
colour(r, g, b, a)(each 0 to 1),colour_hex("#ff8800"),colour_hsv(...),colour_from_gm(c_red);.r .g .b .a,with_alpha,lerp,lightened,darkened,to_gm(). US spellings (color) work too. - Rectangles and boxes:
rect(x, y, w, h)with.left .right .top .bottom .centre .size,contains,overlaps,merged,clipped,grown;box3(min, max)the same in 3D, plusray_hit(origin, dir). - Dictionaries and sets:
dict()takes any value as a key (d[? vec2(3, 4)] = "door"), withget,has,remove,keys,values,size;set()withadd,has,union,intersection,difference.
A project's own function or macro of the same name (function vec3) always wins: the editor then treats the name as the project's.
In the inspector. A Variable Definition (an Expression) whose value is vec2(…), vec3(…), vec4(…), colour(…) or colour_hex("#…") shows as x, y, z fields or a colour well with its alpha, in the object editor and for an instance in a room; Studio writes the value back as code.
In GameMaker builds. GameMaker doesn't know these types, so when a project uses them (or type hints, coroutines, for … in or delta time), Run and Build give GameMaker a copy of the project with that code rewritten as plain GML: the types become small structs and functions in a script Studio adds (scr_studio_types), operators become calls, and hints are taken out. The copy lives in the build folder (gm-source); your own files are never changed, and the Output panel says when a copy was used. A project that uses none of this builds exactly as before. The rewritten code behaves the same as the types do; it is a little slower. Problems in the copy are shown on your own files.
"Can't tell if this is a vector." The rewrite has to know, for each +, -, *, /, comparison and field, whether its values are one of these types or plain numbers. When it can't work that out (a function's argument with no hint, used with an operator, and no call in the project that shows what it is given), Problems shows a warning on that line, for example: can't tell if p is a vector (or another of Studio's types) in p * 2. The rewrite learns a function's argument types from the project's calls; this shows where none of them tells it. It does nothing on Studio Runtime, which always knows, but the GameMaker build might compute the wrong thing. Give the variable a value of its type (p = vec3_zero; in the Create event) or a type hint (function push(p: vec3)), and the warning goes.
Related topics
Keys are shown as on the Mac: ⌘ Command, ⌥ Option, ⌃ Control, ⇧ Shift. Studio for Windows shows its own keys beside each menu item.