{"name":"ctrlSetPosition","operator":null,"title":"ctrlSetPosition","type":"command","url":"https://community.bistudio.com/wiki/ctrlSetPosition","revid":373619,"updated":"2025-05-25T10:19:49Z","groups":["GUI Control - Positioning"],"status":"ok","replaced_by":[],"games":[{"game":"arma1","name":"Armed Assault","version":"1.00"},{"game":"arma2","name":"Arma 2","version":"1.00"},{"game":"arma2oa","name":"Arma 2: Operation Arrowhead","version":"1.50"},{"game":"tkoh","name":"Take On Helicopters","version":"1.00"},{"game":"arma3","name":"Arma 3","version":"0.50"}],"since":{"game":"arma1","name":"Armed Assault","version":"1.00"},"arma3_since":"0.50","branch":null,"locality":{"argument":null,"effect":null,"server_exec":false},"exec":null,"description":"Sets wanted position and size for 2D control animation. Width and height are optional. ctrlCommit is required to complete the operation.\nFor 3D control, param is relative `[x, z, y]` and no ctrlCommit is required as it cannot be animated. If target control is inside a CT_CONTROLS_GROUP, the position needs to be relative to it.\n\n> [!IMPORTANT]\n> This command doesn't work well with CT_MAP control. Use ctrlMapSetPosition instead.","syntaxes":[{"syntax":"controlName ctrlSetPosition [x, y]","since":null,"effect":null,"exec":null,"params":[{"name":"controlName","type":"Control","optional":false,"default":null,"description":"2D control","types":["Control"],"since":null,"text":"controlName: Control - 2D control"},{"name":"x","type":"Number","optional":false,"default":null,"description":"position in x","types":["Number"],"since":null,"text":"x: Number - position in x"},{"name":"y","type":"Number","optional":false,"default":null,"description":"position in y","types":["Number"],"since":null,"text":"y: Number - position in y"}],"returns":{"type":"Nothing","types":["Nothing"],"description":null,"text":"Nothing"},"form":"binary","operator":null,"left":{"text":"controlName","types":["Control"]},"right":{"text":"[x, y]","types":["Array"]}},{"syntax":"controlName ctrlSetPosition [x, y, w, h]","since":null,"effect":null,"exec":null,"params":[{"name":"controlName","type":"Control","optional":false,"default":null,"description":"2D control","types":["Control"],"since":null,"text":"controlName: Control - 2D control"},{"name":"x","type":"Number","optional":false,"default":null,"description":"position in x","types":["Number"],"since":null,"text":"x: Number - position in x"},{"name":"y","type":"Number","optional":false,"default":null,"description":"position in y","types":["Number"],"since":null,"text":"y: Number - position in y"},{"name":"w","type":"Number","optional":false,"default":null,"description":"width of the control","types":["Number"],"since":null,"text":"w: Number - width of the control"},{"name":"h","type":"Number","optional":false,"default":null,"description":"height of the control","types":["Number"],"since":null,"text":"h: Number - height of the control"}],"returns":{"type":"Nothing","types":["Nothing"],"description":null,"text":"Nothing"},"form":"binary","operator":null,"left":{"text":"controlName","types":["Control"]},"right":{"text":"[x, y, w, h]","types":["Array"]}},{"syntax":"controlName ctrlSetPosition [x, z, y]","since":null,"effect":null,"exec":null,"params":[{"name":"controlName","type":"Control","optional":false,"default":null,"description":"3D control","types":["Control"],"since":null,"text":"controlName: Control - 3D control"},{"name":"x","type":"Number","optional":false,"default":null,"description":"screen x","types":["Number"],"since":null,"text":"x: Number - screen x"},{"name":"z","type":"Number","optional":false,"default":null,"description":"distance from the screen (depth). If object is too far, it cannot be dragged by the mouse.","types":["Number"],"since":null,"text":"z: Number - distance from the screen (depth). If object is too far, it cannot be dragged by the mouse."},{"name":"y","type":"Number","optional":false,"default":null,"description":"screen y","types":["Number"],"since":null,"text":"y: Number - screen y"}],"returns":{"type":"Nothing","types":["Nothing"],"description":null,"text":"Nothing"},"form":"binary","operator":null,"left":{"text":"controlName","types":["Control"]},"right":{"text":"[x, z, y]","types":["Array"]}}],"examples":[{"text":"Move control:\n\n```sqf\n_control2D ctrlSetPosition [0, 0];\n_control2D ctrlCommit 0;\n```","code":["_control2D ctrlSetPosition [0, 0];\n_control2D ctrlCommit 0;"]},{"text":"Move control and resize:\n\n```sqf\n_control2D ctrlSetPosition [0, 0, 1, 1];\n_control2D ctrlCommit 0;\n```","code":["_control2D ctrlSetPosition [0, 0, 1, 1];\n_control2D ctrlCommit 0;"]},{"text":"```sqf\n_control3D ctrlSetPosition [0.5, 1, 0.5]; //centered and 1m away from screen\n```","code":["_control3D ctrlSetPosition [0.5, 1, 0.5]; //centered and 1m away from screen"]},{"text":"Typewriter effect:\n\n```sqf\nwith uiNamespace do\n{\n    0 spawn\n    {\n        _text1 = \"This is a simple demo of typewriter text effect with various speed.\";\n        _text2 = \"This took 10 seconds.\";\n        _text3 = \"This is a fast one, set for 2 seconds.\";\n\n        ctrl = findDisplay 46 ctrlCreate [\"RscStructuredText\", -1];\n\n        ctrl ctrlSetPosition [0, 0, 0, 0.1];\n        ctrl ctrlCommit 0;\n        ctrl ctrlSetStructuredText parseText format [\"<t color='#ff0000' size='2.1'>%1</t>\", _text1 splitString \" \" joinString \" \"];\n        ctrl ctrlSetPosition [0, 0, ctrlTextWidth ctrl, 0.1];\n        ctrl ctrlCommit 8;\n\n        waitUntil { ctrlCommitted ctrl };\n        sleep 0.5;\n\n        ctrl ctrlSetPosition [0,0,0,0.1];\n        ctrl ctrlCommit 0;\n        ctrl ctrlSetStructuredText parseText format [\"<t color='#ff0000' size='2.1'>%1</t>\", _text2 splitString \" \" joinString \" \"];\n        ctrl ctrlSetPosition [0, 0, ctrlTextWidth ctrl, 0.1];\n        ctrl ctrlCommit 2;\n\n        waitUntil { ctrlCommitted ctrl };\n        sleep 2;\n\n        ctrl ctrlSetPosition [0,0,0,0.1];\n        ctrl ctrlCommit 0;\n        ctrl ctrlSetStructuredText parseText format [\"<t color='#00ff00' size='2.1'>%1</t>\", _text3 splitString \" \" joinString \" \"];\n        ctrl ctrlSetPosition [0,0,ctrlTextWidth ctrl,0.1];\n        ctrl ctrlCommit 2;\n\n        waitUntil { ctrlCommitted ctrl };\n        sleep 2;\n\n        ctrlDelete ctrl;\n    };\n};\n```","code":["with uiNamespace do\n{\n\t0 spawn\n\t{\n\t\t_text1 = \"This is a simple demo of typewriter text effect with various speed.\";\n\t\t_text2 = \"This took 10 seconds.\";\n\t\t_text3 = \"This is a fast one, set for 2 seconds.\";\n\n\t\tctrl = findDisplay 46 ctrlCreate [\"RscStructuredText\", -1];\n\n\t\tctrl ctrlSetPosition [0, 0, 0, 0.1];\n\t\tctrl ctrlCommit 0;\n\t\tctrl ctrlSetStructuredText parseText format [\"<t color='#ff0000' size='2.1'>%1</t>\", _text1 splitString \" \" joinString \" \"];\n\t\tctrl ctrlSetPosition [0, 0, ctrlTextWidth ctrl, 0.1];\n\t\tctrl ctrlCommit 8;\n\n\t\twaitUntil { ctrlCommitted ctrl };\n\t\tsleep 0.5;\n\n\t\tctrl ctrlSetPosition [0,0,0,0.1];\n\t\tctrl ctrlCommit 0;\n\t\tctrl ctrlSetStructuredText parseText format [\"<t color='#ff0000' size='2.1'>%1</t>\", _text2 splitString \" \" joinString \" \"];\n\t\tctrl ctrlSetPosition [0, 0, ctrlTextWidth ctrl, 0.1];\n\t\tctrl ctrlCommit 2;\n\n\t\twaitUntil { ctrlCommitted ctrl };\n\t\tsleep 2;\n\n\t\tctrl ctrlSetPosition [0,0,0,0.1];\n\t\tctrl ctrlCommit 0;\n\t\tctrl ctrlSetStructuredText parseText format [\"<t color='#00ff00' size='2.1'>%1</t>\", _text3 splitString \" \" joinString \" \"];\n\t\tctrl ctrlSetPosition [0,0,ctrlTextWidth ctrl,0.1];\n\t\tctrl ctrlCommit 2;\n\n\t\twaitUntil { ctrlCommitted ctrl };\n\t\tsleep 2;\n\n\t\tctrlDelete ctrl;\n\t};\n};"]}],"multiplayer":null,"problems":null,"aliases":[],"see_also":["ctrlMapSetPosition","ctrlCommit","ctrlCreate","ctrlDelete","ctrlModel","ctrlSetModel","ctrlPosition","ctrlClassName","displayCtrl","ctrlModelScale","ctrlSetModelScale","ctrlModelDirAndUp","ctrlSetModelDirAndUp"],"notes":[{"user":"Yuval","date":"2017-06-20T11:56:00Z","text":"If the target control is a controls' group, all the child controls of that group will be moved automatically (as their position is relative to the control group rather than the display)."}],"categories":["ArmA: Armed Assault: New Scripting Commands","ArmA: Armed Assault: Scripting Commands","Arma 2: Operation Arrowhead: Scripting Commands","Arma 2: Scripting Commands","Arma 3: Scripting Commands","Command Group: GUI Control - Positioning","Introduced with Armed Assault version 1.00","Scripting Commands","Take On Helicopters: Scripting Commands"]}