Forum
compilation error (*solved*) - Printable Version

+- Forum (https://www.boriel.com/forum)
+-- Forum: Compilers and Computer Languages (https://www.boriel.com/forum/forumdisplay.php?fid=12)
+--- Forum: ZX Basic Compiler (https://www.boriel.com/forum/forumdisplay.php?fid=11)
+---- Forum: Bug Reports (https://www.boriel.com/forum/forumdisplay.php?fid=15)
+---- Thread: compilation error (*solved*) (/showthread.php?tid=483)



compilation error (*solved*) - slenkar - 08-02-2012

I have a compilation eror where it thinks a byte is a label


Re: compilation error - slenkar - 08-02-2012

heres the last files.
compile wars.bas


Re: compilation error - boriel - 08-02-2012

The problem lies in function ChooseNextUnit()

Code:
const NumUnitsIter as Ubyte = 29

Function ChooseNextUnit() as byte
     if LastColorToMove=0 then
         LastColorToMove=red
     end if

    for NumUnitsIter =1 to NumUnits 'NumUnitsIter is a global constant!
        if ActionPoints(NumUnitsIter)=3 then
            UnitMoving=NumUnitsIter
            Exit for
        end if
    next
end function

The FOR loop is using NumsUnitIter as a variable, but it's already declared globally as a const.
You should add the line
Code:
Dim NumUnitsIter as Ubyte
within the function body, so the compiler will understand you want to override the global constant using the same name for a local variable (the global constant NumUnitsIter won't be available within the function). The compiler won't override (declare) the local variable within the function for you (at the moment).
This is a compiler bug, anyway: it should either stop with an error, or issue a warning "Inner declaration hides global constant", or the like. I will fix it later.


Re: compilation error - slenkar - 08-02-2012

thanks :oops:


By the way do you think it will be quicker to:

1. take away 1 from a number,
or
2. get a global variable?


so i can loop through an array with FOR


Re: compilation error - boriel - 08-03-2012

slenkar Wrote:thanks :oops:


By the way do you think it will be quicker to:

1. take away 1 from a number,
or
2. get a global variable?


so i can loop through an array with FOR
I think the 2nd is faster. Anyway, just use DIM within the function and your code is OK! ;-)
(outside the function you will be using the constant).


Re: compilation error - boriel - 08-05-2012

This has been fixed (I think).
Please, download and install the version 1.2.9s910.
Try it and tell me. Wink


Re: compilation error - slenkar - 08-05-2012

yep that works thanks,

it says its not a variable