Your code logic is fine (assuming you didn't mess up the room transitions ~ hard to tell as you don't have them in simple easy-to-see clockwise or counter clockwise order), what's the error/going wrong with it?
the 'while' in quest often causes problems... your guard probably is infinitely moving non-stop... your 'while' loop has nothing to terminate/stop it...
instead, you can either use a (global) Turnscript or add the special 'changed' Script Attribute to your 'player' Player Object, examples in code below
quest has internal turns, which increment (by 1), with every/any clicking of the mouse button on something clickable or entering something you typed-in into the command text box. You can add an Integer Attribute if you want those turns to be seen/displayed to the person playing the game.
(Global) Turnscript:click on the upper left most 'object' (the root) in the left side's "tree of stuff" so it is highlighted (this will make the added Turnscript global: not added to a specific Room Object which would make it a 'local' Turnscript). Then in the menu bar at the top, under 'add', select 'Turnscript', and then add in your same scripting (except remove the 'while' Script from it). Check the 'enabled' check box. Or, you can add in more control over it, but let's not get into that unless you let me know you want to do so.
each internal turn (click or type) the guard will move to the next room, from the moment the game begins. Let me know if you want something different to happen or more control over what happens.
(I added in some extra stuff of my own... ask if you got any questions about any of it or about anything)
<game name="blah">
<attr name="turn" type="int">0</attr>
<status_attributes type="simplestringdictionary">turn = Turn: !</statusattributes>
</game>
// see how the Turnscript below, isn't inside of a Room Object, which makes it a global Turnscript:
<turnscript name="global_turnscript">
<enabled />
<script>
Guard_movement_function
game.turn = game.turn + 1
</script>
</turnscript>
<function name="Guard_movement_function">
if (Guard.movement) { // you don't need to use the '=true', as quest understands this shortened syntax form to be '=true'
if (Guard.parent = NW) {
MoveObject (Guard, N1) // the 'MoveObject' Script/Function and the 'parent' Attribute via 'Guard.parent = N2', do the exact same thing
}
else if (Guard.parent = N1) {
MoveObject (Guard, N2)
}
else if (Guard.parent = N2) {
MoveObject (Guard, N3)
}
else if (Guard.parent = N3) {
MoveObject (Guard, N4)
}
else if (Guard.parent = N4) {
MoveObject (Guard, N5)
}
else if (Guard.parent = N5) {
MoveObject (Guard, NE)
}
else if (Guard.parent = NE) {
MoveObject (GuardU, E1)
}
else if (Guard.parent = E1) {
MoveObject (Guard, E2)
}
else if (Guard.parent = E2) {
MoveObject (Guard, E3)
}
else if (Guard.parent = E3) {
MoveObject (Guard, SE)
}
else if (Guard.parent = SE) {
MoveObject (Guard, S5)
}
else if (Guard.parent = S5) {
MoveObject (Guard, S4)
}
else if (Guard.parent = S4) {
MoveObject (Guard, S3)
}
else if (Guard.parent = S3) {
MoveObject (Guard, S2)
}
else if (Guard.parent = S2) {
MoveObject (Guard, S1)
}
else if (Guard.parent = S1) {
MoveObject (Guard, SW)
}
else if (Guard.parent = SW) {
MoveObject (Guard, W3)
}
else if (Guard.parent = W3) {
MoveObject (Guard, W2)
}
else if (Guard.parent = W2) {
MoveObject (Guard, W1)
}
else if (Guard.parent = W1) {
MoveObject (Guard, NW)
}
}
</function>
the special 'changed' Script Attribute:(too lazy to describe what is going on here at the moment, lol ... hopefully you can figure it out... if not, ask me and I'll help/explain)
<game name="blah">
<attr name="turn" type="int">0</attr>
<status_attributes type="simplestringdictionary">turn = Turn: !</statusattributes>
</game>
<object name="player">
<attr name="changedparent" type="script">
Guard_movement_function
// example: increment_turn_function (1)
</attr>
</object>
// add 'increment_turn_function (type_in_a_number_here_for_how_much_to_increment_your_turn_by)' into where-ever whatever script location you want, or via the GUI~Editor: 'where/what-ever' -> run as script -> add new script -> 'output' category (I believe) -> 'call function' Script -> type your function's name into the small rectangle text box, and however you add in your argument/parameter amount, lol - I'm not familiar with the GUI~Editor
<function name="increment_turn_function" parameters="amount">
if (IsInt (amount)) {
game.turn = game.turn + ToInt (amount)
} else {
msg ("Error in your code: You didn't enter an integer number for its argument/parameter")
}
</function>
<function name="Guard_movement_function">
if (Guard.movement) { // you don't need to use the '=true', as quest understands this shortened syntax form to be '=true'
if (Guard.parent = NW) {
MoveObject (Guard, N1) // the 'MoveObject' Script/Function and the 'parent' Attribute via 'Guard.parent = N2', do the exact same thing
}
else if (Guard.parent = N1) {
MoveObject (Guard, N2)
}
else if (Guard.parent = N2) {
MoveObject (Guard, N3)
}
else if (Guard.parent = N3) {
MoveObject (Guard, N4)
}
else if (Guard.parent = N4) {
MoveObject (Guard, N5)
}
else if (Guard.parent = N5) {
MoveObject (Guard, NE)
}
else if (Guard.parent = NE) {
MoveObject (GuardU, E1)
}
else if (Guard.parent = E1) {
MoveObject (Guard, E2)
}
else if (Guard.parent = E2) {
MoveObject (Guard, E3)
}
else if (Guard.parent = E3) {
MoveObject (Guard, SE)
}
else if (Guard.parent = SE) {
MoveObject (Guard, S5)
}
else if (Guard.parent = S5) {
MoveObject (Guard, S4)
}
else if (Guard.parent = S4) {
MoveObject (Guard, S3)
}
else if (Guard.parent = S3) {
MoveObject (Guard, S2)
}
else if (Guard.parent = S2) {
MoveObject (Guard, S1)
}
else if (Guard.parent = S1) {
MoveObject (Guard, SW)
}
else if (Guard.parent = SW) {
MoveObject (Guard, W3)
}
else if (Guard.parent = W3) {
MoveObject (Guard, W2)
}
else if (Guard.parent = W2) {
MoveObject (Guard, W1)
}
else if (Guard.parent = W1) {
MoveObject (Guard, NW)
}
}
</function>
---------
a different method would be to use List Attribute and its iteration, but List usage is a bit more complex if you're new to quest and especially to coding.
----------
an entirely different method would be to give all of your Room Objects: 'x_coordinate' and 'y_coordinate' (and if you want to do 3D: 'z_coordinate') Integer Attributes, and then handle it in many various ways with coding... not going to get into the methods here though.