Author Topic: Invalid Syntax for ELSE error  (Read 4874 times)

0 Members and 1 Guest are viewing this topic.

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Invalid Syntax for ELSE error
« on: August 30, 2018, 11:48:03 am »
I swear I've had to deal with this error before and it has nothing to do with the ELSE itself. Probably on the .NET forum.
here is the sub generating the error.

Code: QB64: [Select]
  1. SUB DrawSprite(Lx%, Ly%, Mx~%%, MY~%%, Scale%%)
  2.   'get the end map displayed based on scale
  3.  Fx~%% = Mx~%% + (29 \ Scale%%)
  4.  Fy~%% = My~%% + (21 \ Scale%%)
  5.  
  6.  SELECT CASE Unit(0).Movement.IDmark 'Unit(0) sprite layout
  7.   CASE Peasant, Peon, Grunt, Archer, Spearman, Knight, Cleric, Necrolyte, Conjurer, Warlock
  8.    SELECT CASE Unit(0).Movement.Direction 'get base sprite offsets
  9.     CASE North
  10.      SpriteX1% = 0
  11.      SpriteY1% = 0
  12.      SpriteX2% = 31
  13.      SpriteY2% = 31
  14.     CASE NorthEast
  15.      SpriteX1% = 32
  16.      SpriteY1% = 0
  17.      SpriteX2% = 63
  18.      SpriteY2% = 31
  19.     CASE East
  20.      SpriteX1% = 64
  21.      SpriteY1% = 0
  22.      SpriteX2% = 95
  23.      SpriteY2% = 31
  24.     CASE SouthEast
  25.      SpriteX1% = 96
  26.      SpriteY1% = 0
  27.      SpriteX2% = 127
  28.      SpriteY2% = 31
  29.     CASE South
  30.      SpriteX1% = 128
  31.      SpriteY1% = 0
  32.      SpriteX2% = 159
  33.      SpriteY2% = 31
  34.     CASE SouthWest
  35.      SpriteX1% = 127
  36.      SpriteY1% = 0
  37.      SpriteX2% = 96
  38.      SpriteY2% = 31
  39.     CASE West
  40.      SpriteX1% = 95
  41.      SpriteY1% = 0
  42.      SpriteX2% = 64
  43.      SpriteY2% = 31
  44.     CASE NorthWest
  45.      SpriteX1% = 63
  46.      SpriteY1% = 0
  47.      SpriteX2% = 32
  48.      SpriteY2% = 31
  49.    END SELECT
  50.    SELECT CASE Unit(0).Act 'adjust based on unit action
  51.     CASE Still '      unit is not performing an action
  52.     CASE Moving '     unit is walking
  53.      SpriteX1% = SpriteX1%
  54.      SpriteY1% = SpriteY1% + 32 * Anima(0, Unit(0).Movement.Frame)
  55.      SpriteX2% = SpriteX2%
  56.      SpriteY2% = SpriteY2% + 32 * Anima(0, Unit(0).Movement.Frame)
  57.      Unit(0).Movement.Frame = Unit(0).Movement.Frame + 1
  58.      IF Unit(0).Movement.Frame = 8 THEN Unit(0).Movement.Frame = 0
  59.     CASE Mining '     unit is in mine and hidden  Peasant+Peon only
  60.     CASE LumberJack ' unit is chopping wood   Peasant+Peon only
  61.      SpriteX1% = SpriteX1% + 160
  62.      SpriteY1% = SpriteY1% + 32 * Anima(Unit(0).Movement.IDmark, Unit(0).Movement.Frame)
  63.      SpriteX2% = SpriteX2% + 160
  64.      SpriteY2% = SpriteY2% + 32 * Anima(Unit(0).Movement.IDmark, Unit(0).Movement.Frame)
  65.      Unit(0).Movement.Frame = Unit(0).Movement.Frame + 1
  66.      IF Unit(0).Movement.Frame = 8 THEN Unit(0).Movement.Frame = 0
  67.     CASE CarryGold '  unit is carrying bag of gold  Peasant+Peon only
  68.      SpriteX1% = SpriteX1%
  69.      SpriteY1% = SpriteY1% + 320 + 32 * Anima(0, Unit(0).Movement.Frame)
  70.      SpriteX2% = SpriteX2%
  71.      SpriteY2% = SpriteY2% + 320 + 32 * Anima(0, Unit(0).Movement.Frame)
  72.      Unit(0).Movement.Frame = Unit(0).Movement.Frame + 1
  73.      IF Unit(0).Movement.Frame = 8 THEN Unit(0).Movement.Frame = 0
  74.     CASE CarryWood '  unit is carrying a stack of wood  Peasant+Peon only
  75.      SpriteX1% = SpriteX1%
  76.      SpriteY1% = SpriteY1% + 160 + 32 * Anima(0, Unit(0).Movement.Frame)
  77.      SpriteX2% = SpriteX2%
  78.      SpriteY2% = SpriteY2% + 160 + 32 * Anima(0, Unit(0).Movement.Frame)
  79.      Unit(0).Movement.Frame = Unit(0).Movement.Frame + 1
  80.      IF Unit(0).Movement.Frame = 8 THEN Unit(0).Movement.Frame = 0
  81.     CASE Attacking '  unit is attacking
  82.     CASE Shooting '   unit is shooting a projectile
  83.     CASE Casting '    unit is casting a spell
  84.     CASE Decomposing 'unit is dead
  85.    END SELECT
  86.   CASE Footman, Raider
  87.    SELECT CASE Unit(0).Movement.Direction
  88.     CASE North
  89.      SpriteX1% = 0
  90.      SpriteY1% = 0
  91.      SpriteX2% = 47
  92.      SpriteY2% = 47
  93.     CASE NorthEast
  94.      SpriteX1% = 48
  95.      SpriteY1% = 0
  96.      SpriteX2% = 95
  97.      SpriteY2% = 47
  98.     CASE East
  99.      SpriteX1% = 96
  100.      SpriteY1% = 0
  101.      SpriteX2% = 143
  102.      SpriteY2% = 47
  103.     CASE SouthEast
  104.      SpriteX1% = 144
  105.      SpriteY1% = 0
  106.      SpriteX2% = 191
  107.      SpriteY2% = 47
  108.     CASE South
  109.      SpriteX1% = 192
  110.      SpriteY1% = 0
  111.      SpriteX2% = 239
  112.      SpriteY2% = 47
  113.     CASE SouthWest
  114.      SpriteX1% = 191
  115.      SpriteY1% = 0
  116.      SpriteX2% = 144
  117.      SpriteY2% = 47
  118.     CASE West
  119.      SpriteX1% = 143
  120.      SpriteY1% = 0
  121.      SpriteX2% = 96
  122.      SpriteY2% = 47
  123.     CASE NorthWest
  124.      SpriteX1% = 95
  125.      SpriteY1% = 0
  126.      SpriteX2% = 48
  127.      SpriteY2% = 47
  128.    END SELECT
  129.  
  130.  if Unit(0).Movement.MapX < Mx~%% or Unit(0).Movement.MapX > Fx~%% or Unit(0).Movement.MapY < My~%% or Unit(0).Movement.MapY > Fy~%% then
  131.          'unit is not in view
  132.         else
  133.   L%% = Unit(0).Movement.IDmark
  134.  
  135.   UXpos%=Lx%+ ( (Unit(0).Movement.MapX - Mx~%%) * (16*Scale%%) )
  136.   UYpos%=Ly%+ ( (Unit(0).Movement.MapY - My~%%) * (16*Scale%%) )
  137.  
  138.   _PUTIMAGE (UXpos%, UYpos%), Layer(L%%), _DISPLAY, (SpriteX1%, SpriteY1%)-(SpriteX2%, SpriteY2%)
  139.  
  140.  

its the ELSE down by the bottom of the code, now if you notice the else seems monstrously spaced in. It is not as per the IDE or my text editor. Which actually jogs my memory and realize that is the error, for some reason every so often the IDE or my text editor will pop a tab where I space indent things and the IDE freaks out over it. and its very hard to find cause that TAB is hidden on everything on my end, but for some reason it showed up when I pasted it here. and the comment just above also appears to have a hidden TAB in it as well.

BUT that still makes me wonder why the IDE does not like TAB before an ELSE statement?
Granted after becoming radioactive I only have a half-life!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Invalid Syntax for ELSE error
« Reply #1 on: August 30, 2018, 03:51:05 pm »
It's also NOT been syntax checked, as we can tell from previous lines:

Code: QB64: [Select]
  1. if Unit(0).Movement.MapX < Mx~%% or


If the syntax checker had done its thing, these lines would be capitalized, which makes it seem to me as if there's a syntax error, or some such, which should be noticeable in your program before it gets to this point.


For instance, if I define the types so that the syntax checker will complete its run and not error out for me, the code snippet I end up with is this one, instead of your original layout:


Code: QB64: [Select]
  1.  TYPE innerjunk
  2.     IDmark AS INTEGER
  3.     direction AS INTEGER
  4.     frame AS INTEGER
  5.     mapx AS INTEGER
  6.     mapy AS INTEGER
  7.  
  8. TYPE junk
  9.     movement AS innerjunk
  10.     act AS INTEGER
  11.  
  12.  
  13. DIM SHARED unit(10) AS junk
  14.  
  15. SUB DrawSprite (Lx%, Ly%, Mx~%%, MY~%%, Scale%%)
  16.     'get the end map displayed based on scale
  17.     Fx~%% = Mx~%% + (29 \ Scale%%)
  18.     Fy~%% = MY~%% + (21 \ Scale%%)
  19.  
  20.     SELECT CASE unit(0).movement.IDmark 'Unit(0) sprite layout
  21.         CASE Peasant, Peon, Grunt, Archer, Spearman, Knight, Cleric, Necrolyte, Conjurer, Warlock
  22.             SELECT CASE unit(0).movement.direction 'get base sprite offsets
  23.                 CASE North
  24.                     SpriteX1% = 0
  25.                     SpriteY1% = 0
  26.                     SpriteX2% = 31
  27.                     SpriteY2% = 31
  28.                 CASE NorthEast
  29.                     SpriteX1% = 32
  30.                     SpriteY1% = 0
  31.                     SpriteX2% = 63
  32.                     SpriteY2% = 31
  33.                 CASE East
  34.                     SpriteX1% = 64
  35.                     SpriteY1% = 0
  36.                     SpriteX2% = 95
  37.                     SpriteY2% = 31
  38.                 CASE SouthEast
  39.                     SpriteX1% = 96
  40.                     SpriteY1% = 0
  41.                     SpriteX2% = 127
  42.                     SpriteY2% = 31
  43.                 CASE South
  44.                     SpriteX1% = 128
  45.                     SpriteY1% = 0
  46.                     SpriteX2% = 159
  47.                     SpriteY2% = 31
  48.                 CASE SouthWest
  49.                     SpriteX1% = 127
  50.                     SpriteY1% = 0
  51.                     SpriteX2% = 96
  52.                     SpriteY2% = 31
  53.                 CASE West
  54.                     SpriteX1% = 95
  55.                     SpriteY1% = 0
  56.                     SpriteX2% = 64
  57.                     SpriteY2% = 31
  58.                 CASE NorthWest
  59.                     SpriteX1% = 63
  60.                     SpriteY1% = 0
  61.                     SpriteX2% = 32
  62.                     SpriteY2% = 31
  63.             END SELECT
  64.             SELECT CASE unit(0).act 'adjust based on unit action
  65.                 CASE Still '      unit is not performing an action
  66.                 CASE Moving '     unit is walking
  67.                     SpriteX1% = SpriteX1%
  68.                     SpriteY1% = SpriteY1% + 32 * Anima(0, unit(0).movement.frame)
  69.                     SpriteX2% = SpriteX2%
  70.                     SpriteY2% = SpriteY2% + 32 * Anima(0, unit(0).movement.frame)
  71.                     unit(0).movement.frame = unit(0).movement.frame + 1
  72.                     IF unit(0).movement.frame = 8 THEN unit(0).movement.frame = 0
  73.                 CASE Mining '     unit is in mine and hidden  Peasant+Peon only
  74.                 CASE LumberJack ' unit is chopping wood   Peasant+Peon only
  75.                     SpriteX1% = SpriteX1% + 160
  76.                     SpriteY1% = SpriteY1% + 32 * Anima(unit(0).movement.IDmark, unit(0).movement.frame)
  77.                     SpriteX2% = SpriteX2% + 160
  78.                     SpriteY2% = SpriteY2% + 32 * Anima(unit(0).movement.IDmark, unit(0).movement.frame)
  79.                     unit(0).movement.frame = unit(0).movement.frame + 1
  80.                     IF unit(0).movement.frame = 8 THEN unit(0).movement.frame = 0
  81.                 CASE CarryGold '  unit is carrying bag of gold  Peasant+Peon only
  82.                     SpriteX1% = SpriteX1%
  83.                     SpriteY1% = SpriteY1% + 320 + 32 * Anima(0, unit(0).movement.frame)
  84.                     SpriteX2% = SpriteX2%
  85.                     SpriteY2% = SpriteY2% + 320 + 32 * Anima(0, unit(0).movement.frame)
  86.                     unit(0).movement.frame = unit(0).movement.frame + 1
  87.                     IF unit(0).movement.frame = 8 THEN unit(0).movement.frame = 0
  88.                 CASE CarryWood '  unit is carrying a stack of wood  Peasant+Peon only
  89.                     SpriteX1% = SpriteX1%
  90.                     SpriteY1% = SpriteY1% + 160 + 32 * Anima(0, unit(0).movement.frame)
  91.                     SpriteX2% = SpriteX2%
  92.                     SpriteY2% = SpriteY2% + 160 + 32 * Anima(0, unit(0).movement.frame)
  93.                     unit(0).movement.frame = unit(0).movement.frame + 1
  94.                     IF unit(0).movement.frame = 8 THEN unit(0).movement.frame = 0
  95.                 CASE Attacking '  unit is attacking
  96.                 CASE Shooting '   unit is shooting a projectile
  97.                 CASE Casting '    unit is casting a spell
  98.                 CASE Decomposing 'unit is dead
  99.             END SELECT
  100.         CASE Footman, Raider
  101.             SELECT CASE unit(0).movement.direction
  102.                 CASE North
  103.                     SpriteX1% = 0
  104.                     SpriteY1% = 0
  105.                     SpriteX2% = 47
  106.                     SpriteY2% = 47
  107.                 CASE NorthEast
  108.                     SpriteX1% = 48
  109.                     SpriteY1% = 0
  110.                     SpriteX2% = 95
  111.                     SpriteY2% = 47
  112.                 CASE East
  113.                     SpriteX1% = 96
  114.                     SpriteY1% = 0
  115.                     SpriteX2% = 143
  116.                     SpriteY2% = 47
  117.                 CASE SouthEast
  118.                     SpriteX1% = 144
  119.                     SpriteY1% = 0
  120.                     SpriteX2% = 191
  121.                     SpriteY2% = 47
  122.                 CASE South
  123.                     SpriteX1% = 192
  124.                     SpriteY1% = 0
  125.                     SpriteX2% = 239
  126.                     SpriteY2% = 47
  127.                 CASE SouthWest
  128.                     SpriteX1% = 191
  129.                     SpriteY1% = 0
  130.                     SpriteX2% = 144
  131.                     SpriteY2% = 47
  132.                 CASE West
  133.                     SpriteX1% = 143
  134.                     SpriteY1% = 0
  135.                     SpriteX2% = 96
  136.                     SpriteY2% = 47
  137.                 CASE NorthWest
  138.                     SpriteX1% = 95
  139.                     SpriteY1% = 0
  140.                     SpriteX2% = 48
  141.                     SpriteY2% = 47
  142.             END SELECT
  143.     END SELECT
  144.  
  145.     IF unit(0).movement.mapx < Mx~%% OR unit(0).movement.mapx > Fx~%% OR unit(0).movement.mapy < MY~%% OR unit(0).movement.mapy > Fy~%% THEN
  146.         'unit is not in view
  147.     ELSE
  148.         L%% = unit(0).movement.IDmark
  149.  
  150.         UXpos% = Lx% + ((unit(0).movement.mapx - Mx~%%) * (16 * Scale%%))
  151.         UYpos% = Ly% + ((unit(0).movement.mapy - MY~%%) * (16 * Scale%%))
  152.  
  153.         _PUTIMAGE (UXpos%, UYpos%), Layer(L%%), _DISPLAY, (SpriteX1%, SpriteY1%)-(SpriteX2%, SpriteY2%)
  154.     END IF
  155.  
  156.  


https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

FellippeHeitor

  • Guest
Re: Invalid Syntax for ELSE error
« Reply #2 on: August 30, 2018, 04:26:03 pm »
I don't get it. Both if I load a file with hard TAB characters or if I paste a snippet with hard TAB characters these will be converted by the IDE into spaces. What is your method here?

This attachment contains indentation made with TAB in Windows' Notepad:   [ You are not allowed to view this attachment ]  

Does it not load properly in your IDE? What other steps must be taken to reproduce the issue?

FellippeHeitor

  • Guest
Re: Invalid Syntax for ELSE error
« Reply #3 on: August 30, 2018, 04:32:20 pm »
PS: Command-line compiling it with qb64 -c tabElse.txt also works here, so the compiler is fine with it too.

PS2: What version of QB64?

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Invalid Syntax for ELSE error
« Reply #4 on: August 30, 2018, 09:03:45 pm »
okay,
It's also NOT been syntax checked, as we can tell from previous lines:

Code: QB64: [Select]
  1. if Unit(0).Movement.MapX < Mx~%% or

If the syntax checker had done its thing, these lines would be capitalized, which makes it seem to me as if there's a syntax error, or some such, which should be noticeable in your program before it gets to this point.

That is because this section of code was added after I turned this sub into an include file, that IF-THEN section was typed in my Hex editor. Once I get a SUB or FUNCTION working I pull it from the main code and turn it into an include, freeing up the IDE space. from time to time I change something in the main code that requires some changes to the included subs and for that I use the Hex editor. this time the issue was caused by that editor. but that is why the If then section wasn't syntax checked while the rest is.

Felli, I am including the code necessary to make the error show up, I started this project with Build 20171116/82 and will probably finish it with that version, then the move to a more recent release for the next project. though I am pretty sure this happened on an even earlier version too but cant remember just when it happened last time.(I'll test it with the current DB just to be thorough but I doubt this issue has been addressed as I doubt it comes up that often. will add response once done.)
I also included a snap shot of what my editor shows me when I copied the original posted code and pasted it back into my editor, and thats why this is so hard for me to catch right off cause it shows everything spaced just how I wanted it and I never use the tab key.

Hey if you want to check out some of the test animation change 'DrawSpriteerror.bi' to 'DrawSprite.bi' and watch the peasant follow his path around the trees! its still pretty rough but the pathfinding and animation are working together!
Granted after becoming radioactive I only have a half-life!

FellippeHeitor

  • Guest
Re: Invalid Syntax for ELSE error
« Reply #5 on: August 30, 2018, 09:13:22 pm »
WarCraft64.bas compiled just fine from the command line; It was loading it inside the IDE that showed the error you report, which indicates it's when parsing an INCLUDE that TABs get in the way. That makes it clearer now, thanks.

Workarounds for your workflow to be able to move forward:
1- When the faulty included file is indicated by the IDE, double-clicking it launches a second instance of QB64 with the faulty file loaded and the faulty line highlighted. Ctrl+S or File->Save and the issue is gone.

2- none of this would have showed up if you were compiling via command line; since you use an external edit tool, you can probably set it up to trigger qb64 -x yourprogram.bas without having to leave it; that can be useful especially since the compiler doesn't have an issue with TAB before else any longer; that's just the IDE that'll need fixing.

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Invalid Syntax for ELSE error
« Reply #6 on: August 30, 2018, 09:38:57 pm »
WarCraft64.bas compiled just fine from the command line; It was loading it inside the IDE that showed the error you report, which indicates it's when parsing an INCLUDE that TABs get in the way. That makes it clearer now, thanks.

Workarounds for your workflow to be able to move forward:
1- When the faulty included file is indicated by the IDE, double-clicking it launches a second instance of QB64 with the faulty file loaded and the faulty line highlighted. Ctrl+S or File->Save and the issue is gone.

2- none of this would have showed up if you were compiling via command line; since you use an external edit tool, you can probably set it up to trigger qb64 -x yourprogram.bas without having to leave it; that can be useful especially since the compiler doesn't have an issue with TAB before else any longer; that's just the IDE that'll need fixing.

1- yeah fix is easy, but still doesn't show up in the IDE window that opened for me and  my machine doesn't like it slows down a bit, usually cant have two IDEs open with anything else going, shes just old and gettin clunky., but not an issue to fix, simple backspace and new space the the tab is gone.

2- Yeah, no my editor is 25 years old. doesn't have anything like that but it does allow me to have multiple files open at the same time and display in both text and HEX so I still use it(not to mention it was paid for back then). and I'm still developing the main body of code within the IDE the only things I mess with in the editor is the subs I've turned into includes, and as for double clicking within the ide see number 1.

any idea as to why the IDE would throw a fit about it though?
Granted after becoming radioactive I only have a half-life!

FellippeHeitor

  • Guest
Re: Invalid Syntax for ELSE error
« Reply #7 on: August 30, 2018, 10:07:05 pm »
any idea as to why the IDE would throw a fit about it though?

It'd have to manually account for that corner case and ignore it. I made the compiler ignore it a while back, but that hadn't popped like this in the IDE for me before. A future release may bring it fixed, hopefully.