missing operand on SET/A

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
einstein1969
Expert
Posts: 961
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

missing operand on SET/A

#1 Post by einstein1969 » 08 Jun 2016 05:02

Hi to all

I have a problem on this code

Code: Select all

setlocal EnableDelayedExpansion

rem I need use DelayedExpansion because the follow it's used in FOR loops!

set /A from=-32, distance=7, side=1

rem set /A ray[!from!].dist=distance, ray[!from!].side=side
set /A ray[!from!].dist=distance

pause


result:

Code: Select all

C:\Users\ACER\Desktop>setlocal EnableDelayedExpansion
C:\Users\ACER\Desktop>rem I need use DelayedExpansion because the follow it's used in FOR loops!
C:\Users\ACER\Desktop>set /A from=-32, distance=7, side=1
C:\Users\ACER\Desktop>rem set /A ray[!from!].dist=distance, ray[!from!].side=side
C:\Users\ACER\Desktop>set /A ray[!from!].dist=distance
Operatore mancante.

C:\Users\ACER\Desktop>pause
Premere un tasto per continuare . . .


I need use DelayedExpansion because it's used in FOR loops.
Why there is error?
How I can resolve?

einstein1969

einstein1969
Expert
Posts: 961
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: missing operand on SET/A

#2 Post by einstein1969 » 08 Jun 2016 05:09

simplify

This not work :? :cry:

Code: Select all

set /A ray[-32]=4


output:

Code: Select all

C:\Users\ACER>set /A ray[-32]=4
Operatore mancante.



Extracted of complete code:

Code: Select all

:raypacket
 rem stack calls
 set /A c=0 & :: empty stack
 rem push(calls, (from, to))
 set /A c+=1
 set calls[%c%].1=!from!
 set calls[%c%].2=!to!
 set Break=
 rem 65=Field of View 0..64
 rem simulate while not empty(calls) do
 echo qui0
 For /L %%N in (0,1,64) do if not defined Break (
  rem (from, to) = pop(calls)
  set /A from=calls[!c!].1, to=calls[!c!].2, c-=1
  rem if from = to then raytraverse(from)  //simple problem
  if !from! equ !to! (
      echo qui1
      rem TODO check if already traverse
      set /A "Z=from, aStepY=%SIN(x):x=Z * 31416 / 180%, aStepX=%SIN(x):x=15708-(Z * 31416 / 180)%"
      set /A "A=%Angle%, corr=%SIN(x):x=15708-(Z-A) * 31416 / 180%"
      call :new_prepareDDA_raytraverse
      set /A ray[!from!].dist=distance, ray[!from!].side=side, ray[!from!].C=$B
  ) else (
    echo qui2
    set /A diff=from-to
    if !diff! equ 1 (
      echo qui3
      rem TODO check if already traverse
      set /A "Z=from, aStepY=%SIN(x):x=Z * 31416 / 180%, aStepX=%SIN(x):x=15708-(Z * 31416 / 180)%"
      set /A "A=%Angle%, corr=%SIN(x):x=15708-(Z-A) * 31416 / 180%"
      call :new_prepareDDA_raytraverse
      set /A ray[!from!].dist=distance, ray[!from!].side=side, ray[!from!].C=$B
      set from+=1

      rem TODO check if already traverse
      set /A "Z=from, aStepY=%SIN(x):x=Z * 31416 / 180%, aStepX=%SIN(x):x=15708-(Z * 31416 / 180)%"
      set /A "A=%Angle%, corr=%SIN(x):x=15708-(Z-A) * 31416 / 180%"
      call :new_prepareDDA_raytraverse
      set /A ray[!from!].dist=distance, ray[!from!].side=side, ray[!from!].C=$B
    ) else (
        echo qui4
        rem destination1=raytraverse(from)
        rem TODO check if already traverse
        set /A "Z=from, aStepY=%SIN(x):x=Z * 31416 / 180%, aStepX=%SIN(x):x=15708-(Z * 31416 / 180)%"
        set /A "A=%Angle%, corr=%SIN(x):x=15708-(Z-A) * 31416 / 180%"
echo newprep
        call :new_prepareDDA_raytraverse
echo set1
        echo !distance! !side! !$B! !from! -
        set /A ray[!from!].dist=distance, ray[!from!].side=side, ray[!from!].C=!$B!
echo setdest1
        set dest1=!side! !$X! !$Y!
echo mezzo qui4
        rem destination2=raytraverse(to)
        rem TODO check if already traverse
        set /A "Z=to, aStepY=%SIN(x):x=Z * 31416 / 180%, aStepX=%SIN(x):x=15708-(Z * 31416 / 180)%"
        set /A "A=%Angle%, corr=%SIN(x):x=15708-(Z-A) * 31416 / 180%"
        call :new_prepareDDA_raytraverse
        set /A ray[!to!].dist=distance, ray[!to!].side=side, ray[!to!].C=$B
        set dest2=!side! !$X! !$Y!
echo fine qui4
        rem if destination1=destination2 then
        if "!dest1!"=="!dest2!" (
            echo qui5
            rem linear_interpolate_distance(from,to)
            rem https://en.wikipedia.org/wiki/Linear_interpolation
            set /A x0=from, x1=to, y0=0
        ) else (
          echo qui6
          rem push(calls, (from+(to-from)/2+1,to))
          rem push(calls, (from,from+(to-from)/2))
        )
    )
  )
  if !c! equ 0 set Break=True
 )
exit /b

jeb
Expert
Posts: 1055
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

Re: missing operand on SET/A

#3 Post by jeb » 08 Jun 2016 05:25

I expected that your ray[-32] can't work.

Else how the set /a should evaluate

Code: Select all

set /a ]=1
set /a ray[=666
set /a ray[-32]=4

set /a result=ray[-32]

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: missing operand on SET/A

#4 Post by penpen » 08 Jun 2016 05:48

You could use a workaround like this:

Code: Select all

set /A ray[!from:-=_!].dist=distance


penpen

einstein1969
Expert
Posts: 961
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: missing operand on SET/A

#5 Post by einstein1969 » 08 Jun 2016 08:56

jeb wrote:I expected that your ray[-32] can't work.

Else how the set /a should evaluate

Code: Select all

set /a ]=1
set /a ray[=666
set /a ray[-32]=4

set /a result=ray[-32]


I can't understand what you means....

einstein1969
Expert
Posts: 961
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: missing operand on SET/A

#6 Post by einstein1969 » 08 Jun 2016 09:08

penpen wrote:You could use a workaround like this:

Code: Select all

set /A ray[!from:-=_!].dist=distance


penpen


thanks penpen...

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: missing operand on SET/A

#7 Post by foxidrive » 08 Jun 2016 10:36

einstein1969 wrote:
jeb wrote:I expected that your ray[-32] can't work.


I can't understand what you means....


I believe it is a parsing issue where the -32 can be interpreted as a mathematical expression.

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: missing operand on SET/A

#8 Post by penpen » 08 Jun 2016 17:16

Yes it's parsing related: The lexical scanner (typically) stops recognizing names at each math operator (such as "-"), so:
- "ray[" is a name,
- "-" is an operator,
- "32" is a number,
- and "]" is again a name.
You cannot solve it in another way, except if you use a "context sensitive scanner";
but that's improbable, because they are very slow.
(And "[]" is no known operator in "set/a", so a context sensitive scanner would be of no use here.)

penpen

einstein1969
Expert
Posts: 961
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: missing operand on SET/A

#9 Post by einstein1969 » 15 Jun 2016 11:36

I have another problem:

When I need to reuse the calculated value I get "missing operator"

Code: Select all

setlocal EnableDelayedExpansion

set /A from=-32, distance=7, side=1

set /A ray[!from:-=_!].dist=distance, ray[!from:-=_!].side=side

For /L %%Z in (-32,1,-32) do (

  set /A distance=ray[%%Z].dist, side=ray[%%Z].side

)


I need to use in a loop from -32 to 32. I have show a single case.

Why?
How can resolve this?
how to use variable substitute with a loop variable?

eDIT: sorry I have do a error using lovercase %%Z. I have re-edit the post. :oops:

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: missing operand on SET/A

#10 Post by Squashman » 15 Jun 2016 11:56

Your variable names are:
ray[_32].dist
ray[_32].side

But you are trying to reference.
ray[-32].dist
ray[-32].side

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: missing operand on SET/A

#11 Post by aGerman » 15 Jun 2016 12:37

In addition to what Squashman said you already know that the - was interpreted as operator. For that reason you already had to replace - with _. Since you cant replace it directly in a FOR variable you have to assign your number to a temporary environment variable (e.g. !Z!) beforehand.

Code: Select all

For /L %%Z in (-32,1,32) do (
  set "Z=%%Z"
  set /A distance=ray[!Z:-=_!].dist, side=ray[!Z:-=_!].side
  echo !distance! !side!
)


Regards
aGerman

einstein1969
Expert
Posts: 961
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: missing operand on SET/A

#12 Post by einstein1969 » 15 Jun 2016 15:53

thanks squashman, thanks aGerman.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: missing operand on SET/A

#13 Post by aGerman » 15 Jun 2016 16:10

Even if I don't know what your code is for ...
Did you think about using an offset? E.g. if your range is always -32...32 you may use an offset of +32 in order to get only unsigned values 0...64 that should work in your variables without string manipulations. Just an idea though ...

Regards
aGerman

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: missing operand on SET/A

#14 Post by foxidrive » 15 Jun 2016 23:56

aGerman wrote:Even if I don't know what your code is for ...


Me neither, but einstein1969 does some mind boggling work in his 3D maze and radar scripts.

einstein1969
Expert
Posts: 961
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: missing operand on SET/A

#15 Post by einstein1969 » 16 Jun 2016 10:35

@aGerman
the offset is used for calculate a SIN value. I'll probe your suggest, even I have seriuos problem with my mind. I develop one line every 4-5week.

@foxidrive
Yuo are correct. Is the new core of dos batch 3D raycast. I hope to double or triple the speed with this algorithm.

Post Reply