Skip to main content

Loops not excecuting

Comments

4 comments

  • Ernie Support
    Support

    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
  • f s

    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
  • Ernie Support
    Support

    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
  • Debbie Alexander
    Moderator Beacon of Knowledge Super Star
    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.