# Gui.set\_rotation() documentation

**URL:** <https://forum.defold.com/t/gui-set-rotation-documentation/68669>\
**Category:** Questions\
**Created:** [June 21, 2021, 8:46am UTC](https://forum.defold.com/t/gui-set-rotation-documentation/68669 "2021-06-21T08:46:29Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![totebo](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/totebo/32/36087_2.png) [@totebo](https://forum.defold.com/u/totebo)\
**Post date:** [June 21, 2021, 8:46am UTC](https://forum.defold.com/t/gui-set-rotation-documentation/68669/1 "2021-06-21T08:46:29Z")

</div>

Here is an old chestnut that continues to confuse me. Let’s make this Enlightenment Monday!

From the [documentation](https://defold.com/ref/gui/#gui.set_rotation:node-rotation):

> #### gui.set\_rotation()
> 
> `gui.set_rotation(node,rotation)`
> 
> Sets the rotation of the supplied node. The rotation is expressed in degree Euler angles.

Using a euler z number throws an error:

```
local euler_z = math.atan2(unlocked_level_node_position.y-level_node_position.y, unlocked_level_node_position.x-level_node_position.x)
--gui.set_rotation(node, euler_z) -- ERROR:SCRIPT: /screens/map/map.gui_script:36: bad argument #2 to 'set_rotation' (quat expected, got number)
local rotation = vmath.quat_rotation_z(euler_z)
gui.set_rotation(node, rotation) 

```

Converting the euler z to a quaternion works. Two questions:

Does “degree Euler angles” actually mean a quaternion?

Wouldn’t it make sense to use a number, either euler z or radians, in gui, since it’s in 2D space only?

---

<div class="post-metadata">

**Author:** ![Mathias\_Westerdahl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/mathias_westerdahl/32/228_2.png) [@Mathias\_Westerdahl](https://forum.defold.com/u/Mathias_Westerdahl)\
**Post date:** [June 21, 2021, 8:58am UTC](https://forum.defold.com/t/gui-set-rotation-documentation/68669/2 "2021-06-21T08:58:14Z")

</div>

For consistency, we should change the documentation to mention a quaternion.

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [June 21, 2021, 9:02am UTC](https://forum.defold.com/t/gui-set-rotation-documentation/68669/3 "2021-06-21T09:02:20Z")

</div>

The API reference doesn’t say what type rotation should be in when calling gui.set\_rotation(node, rotation) (I’ll fix this!).

> **[gui.set\_rotation() - API reference (GUI)](https://defold.com/ref/stable/gui/#gui.set_rotation:node-rotation)**
>
> gui.set\_rotation(node,rotation) | Defold is a free and open game engine used for development of console, desktop, mobile and web games.

The code does however enlighten us:

> <https://github.com/defold/defold/blob/dev/engine/gui/src/gui_script.cpp#L3373-L3380>

And if we look at the implementation there’s three code paths:

> <https://github.com/defold/defold/blob/dev/engine/gui/src/gui_script.cpp#L3536-L3548>

So rotation is either a vector3, vector4 or a quaternion. And in the case of a quaternion it is converted to a v4 with euler angles.

---

<div class="post-metadata">

**Author:** ![totebo](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/totebo/32/36087_2.png) [@totebo](https://forum.defold.com/u/totebo)\
**Post date:** [June 21, 2021, 9:23am UTC](https://forum.defold.com/t/gui-set-rotation-documentation/68669/4 "2021-06-21T09:23:58Z")

</div>

Nice, thanks for that, I feel much more enlightened.

One final note, I’m a bit jealous of gui.animate() since it accepts a “rotation.z” number as an argument, as well as vectors:

```
gui.animate(node, "rotation.z", 180, gui.EASING_INOUTSINE, 1)
gui.animate(node, "rotation", vmath.vector3(0,0,180), gui.EASING_INOUTSINE, 1)
gui.animate(node, "rotation", vmath.vector4(0,0,180,0), gui.EASING_INOUTSINE, 1)

```

In the go space I tend to use `go.set(".", "euler.z", 180)`, but this is not possible in gui space because there is no gui.set(). I think this is related to the gui.property() issue [here](https://github.com/defold/defold/issues/4068).

Needless to say, I’m a fan of numbers. 🙂

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [June 21, 2021, 9:58am UTC](https://forum.defold.com/t/gui-set-rotation-documentation/68669/5 "2021-06-21T09:58:17Z")

</div>

> [@totebo](#):
>
> One final note, I’m a bit jealous of gui.animate() since it accepts a “rotation.z” number as an argument, as well as vectors

But go.animate() does this as well?

> [@totebo](#):
>
> this is not possible in gui space because there is no gui.set(). I think this is related to the gui.property() issue [here](https://github.com/defold/defold/issues/4068)

Yes, and this: [go.set equivalent in gui namespace · Issue #5090 · defold/defold · GitHub](https://github.com/defold/defold/issues/5090)

---

<div class="post-metadata">

**Author:** ![totebo](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/totebo/32/36087_2.png) [@totebo](https://forum.defold.com/u/totebo)\
**Post date:** [June 21, 2021, 10:23am UTC](https://forum.defold.com/t/gui-set-rotation-documentation/68669/6 "2021-06-21T10:23:43Z")

</div>

> [@britzl](#):
>
> But go.animate() does this as well?

Yeah, I mention is because of the lack of a gui.set() which you sent an even better link to. Upvote!

---

<div class="post-metadata">

**Author:** ![ross.grams](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/r/cab0a1/32.png) [@ross.grams](https://forum.defold.com/u/ross.grams)\
**Post date:** [June 22, 2021, 3:42pm UTC](https://forum.defold.com/t/gui-set-rotation-documentation/68669/7 "2021-06-22T15:42:20Z")

</div>

…even though I read this yesterday, I still ran headfirst into it myself. 🤦‍♂️

On a more general note, it would be great if _all_ the parameters and return values in the API docs had their types specified. The current names and descriptions are not very helpful.

Like [gui.get\_layer()](https://defold.com/ref/stable/gui/#gui.get_layer:node):  
**RETURNS**

`layer` layer id

You still have no idea what `layer` is! String? Number? Hash? (it’s a hash.)

I’d be happy to help work on this, but I don’t know anything about where the API docs are written or how they’re generated, etc.

---

<div class="post-metadata">

**Author:** ![Mathias\_Westerdahl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/mathias_westerdahl/32/228_2.png) [@Mathias\_Westerdahl](https://forum.defold.com/u/Mathias_Westerdahl)\
**Post date:** [June 22, 2021, 4:17pm UTC](https://forum.defold.com/t/gui-set-rotation-documentation/68669/8 "2021-06-22T16:17:18Z")

</div>

The reason is that the type currently isn’t shown for some reason. Not sure when that broke. Here is the actual source documentation:

> <https://github.com/defold/defold/blob/dev/engine/gui/src/gui_script.cpp#L1925-L1931>

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [June 22, 2021, 5:01pm UTC](https://forum.defold.com/t/gui-set-rotation-documentation/68669/9 "2021-06-22T17:01:39Z")

</div>

> [@Mathias\_Westerdahl](#):
>
> The reason is that the type currently isn’t shown for some reason. Not sure when that broke

I’ll look into this!

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [June 23, 2021, 6:21am UTC](https://forum.defold.com/t/gui-set-rotation-documentation/68669/10 "2021-06-23T06:21:49Z")

</div>

> [@britzl](#):
>
> I’ll look into this!

The API reference has now been updated to include types for all parameters
