Loops not excecuting
i'm working on a school project, which is using code to drive the story forward and add title cards, which would be great but when i run my code, loops do not work.
function display_actionbar () {which looks like
player.execute(
"/title @s actionbar " + leavingroom
)
player.say(":)")
}
function show_title () {
detect_player_between(15, -60, 22, 15, -60, 24)
if (leavingroom == "false") {
leavingroom = "true"
player.execute(
"/title @s title §nGym"
)
}
}
function leaving_room () {
detect_player_between(14, -60, 22, 10, -60, 24)
if (leavingroom == "true") {
leavingroom = "false"
}
}
function detect_player_between (x: number, y: number, z: number, _1x: number, _1y: number, _1z: number) {
while (!(posZ >= z && posZ <= _1z && (posX >= x && posX <= _1x && (posY >= y && posY <= _1y)))) {
}
}
function sync_pos_var () {
posX = player.position().getValue(Axis.X)
posY = player.position().getValue(Axis.Y)
posZ = player.position().getValue(Axis.Z)
}
let posY = 0
let posX = 0
let posZ = 0
let leavingroom = ""
while (0 == 0) {
sync_pos_var()
leaving_room()
show_title()
display_actionbar()
}
-
Hey there,
We are going to take a look at this code, but in the meantime, could you tell me what error you are receiving when you try to run it?
0 -
no error message, maybe loops would run one cycle, then wouldnt work. anything looping doesnt work and i have no idea why. the code does run but loops dont work
0 -
Looks like the error lies within the second loop.
One of my team members took a look at it and wrote something up for you. Give this code a try:
He remarked "the insideRoom variable can be used to mark whether you've been in the room if you mean to do something with rather linear progression"
I hope this helps!0 -
function display_actionbar () {
player.execute(
"/title @s actionbar " + leavingroom
)
player.say(":)")
}
function show_title () {
detect_player_between(15, -60, 22, 15, -60, 24)
if (leavingroom == "false") { // THIS is the only place where leavingroom changes
// however, the initial value was "" so how can it execute?
leavingroom = "true"
player.execute(
"/title @s title §nGym"
)
}
}
function leaving_room () {
detect_player_between(14, -60, 22, 10, -60, 24)
if (leavingroom == "true") { //nothing happens unless leavingroom has changed
leavingroom = "false"
}
}
function detect_player_between (x: number, y: number, z: number, _1x: number, _1y: number, _1z: number) {
while (!(posZ >= z && posZ <= _1z && (posX >= x && posX <= _1x && (posY >= y && posY <= _1y)))) {
} // this is an empty block, right? so nothing happens here.
}
function sync_pos_var () {
posX = player.position().getValue(Axis.X)
posY = player.position().getValue(Axis.Y)
posZ = player.position().getValue(Axis.Z)
}
let posY = 0
let posX = 0
let posZ = 0
let leavingroom = "" // until this is changed this controls everything!
while (0 == 0) {
sync_pos_var() // this sets up three variables
leaving_room() // this does not have effect; see comments in functions
show_title() // this only executes if leavingroom has changed!
display_actionbar()
}0
Please sign in to leave a comment.
Comments
4 comments