Navigation

    Fuze Arena Logo
    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Users
    • Groups
    • Help
    • Discord

    Unexpected variable error

    Beginners
    \\\ \\\
    4
    9
    251
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A
      ahallett2002 last edited by ahallett2002

      Hey guys,

      I'm trying to make a space shooters game and it is giving me an unexpected variable error.
      I have finished coding the game. Here is my code where it is giving me an error.

      if moveEnemy==true then
      enemies[enemyCount].x += ((85/alienSpace) * enemyDirection)
      endif
      setSpriteLocation(enemies[enemyCount], { enemies[enemyCount].x, enemies[enemyCount].y } )
      If (enemies[enemyCount].x > gwidth() - 50 or enemies[enemyCount].x < 50) and getSpriteVisibility(enemies[enemyCount])
      dropRow = true
      endif

      1 Reply Last reply Reply Quote 1
      • pianofire
        pianofire Fuze Team last edited by

        @ahallett2002 It is difficult to tell from this code snippet. I think we will need to see some more. I suspect that enemyCount is a loop counter. If it is a for loop it needs to go from 0 to the length of your enemies array. You must have first called createSprite() for every entry in the array.

        1 Reply Last reply Reply Quote 0
        • PickleCatStars
          PickleCatStars F last edited by

          I’ve had this when I forget to write ‘loop’ or ‘then’ ...

          1 Reply Last reply Reply Quote 0
          • Martin
            Martin Fuze Team last edited by

            You're missing a "then" on the end of the "If" line, hence dropRow is unexpected.

            For what it's worth, this is completely unnecessary too:
            setSpriteLocation(enemies[enemyCount], { enemies[enemyCount].x, enemies[enemyCount].y } )

            What you're doing there is saying "hey, set sprite.x to sprite.x". Or in other words, enemies[enemyCount].x += ((85/alienSpace) * enemyDirection) directly sets the x position of the sprite, you don't need to call the setSpriteLocation method just to be sure.

            A 1 Reply Last reply Reply Quote 1
            • A
              ahallett2002 @Martin last edited by Martin

              @Martin thanks! That got rid of the error. Now its giving me an error for the repeat function

              Code:

              printAt(0.0,enemyMoveCounter,"---"-alienSpeed)
              If dropRow then
                  enemyDirection *= -1 
                  for enemyCount=0 to 40 loop
                      enemies[enemyCount].y += 50
                      enemies[enemyCount].x ((85/aliensSpace * enemyDirection)
              
                      dropRow = false 
                  repeat
              
              1 Reply Last reply Reply Quote 1
              • Martin
                Martin Fuze Team last edited by Martin

                I've added the backticks to display it properly and also indented it properly.

                It should be obvious what the error is telling you now :)

                [edit] Actually, I can see five errors altogether, but maybe some are just typos?

                1 Reply Last reply Reply Quote 0
                • Martin
                  Martin Fuze Team last edited by Martin

                  Let's see if I can type this without error - the line where you modify X will be a guess as to what you actually want to do...

                  printAt(0, 0, enemyMoveCounter, "---", -alienSpeed)    // you were missing a comma after 0 and after the second "
                  If dropRow then
                      enemyDirection *= -1 
                      for enemyCount = 0 to 40 loop
                          enemies[enemyCount].y += 50
                          enemies[enemyCount].x = ((85 / aliensSpace) * enemyDirection)  // = was missing and close bracket after aliensSpace
                      repeat
                  
                      dropRow = false 
                  
                  endif    // was missing - suspect this was the real problem
                  
                  1 Reply Last reply Reply Quote 0
                  • Martin
                    Martin Fuze Team last edited by Martin

                    I'm also guessing there's a logic issue there because you're only checking drawRow once in the outer if statement and yet you are setting it to false 40 times in the for loop. Either you mean it to do something different to what it is doing or it could be moved to the line between the repeat and the endif, thus only setting it to false once. I've modified my answer.

                    A 1 Reply Last reply Reply Quote 1
                    • A
                      ahallett2002 @Martin last edited by

                      @Martin yes it was, thanks for the edit. The game works perfectly fine now!!

                      1 Reply Last reply Reply Quote 1
                      • First post
                        Last post