开发者

Bat not liking "," for x,y,c

开发者 https://www.devze.com 2023-04-12 05:44 出处:网络
I\'m making a bat game, and for the location of the player im using x.y.c (C being the compass the player is facing) Note the use of \".\" and not \",\"

I'm making a bat game, and for the location of the player im using x.y.c (C being the compass the player is facing) Note the use of "." and not ","

Why is it that batch doesn't like the use of ","?

What I mean by this is if you say开发者_运维知识库 goto 0,0 it will crash because it cant find :0,0 However if you use goto 0.0 it can find :0.0


Labels cannot contain a ,. This is not just in batch. 'Real' programming languages generally also don't accept the use of a comma in identifiers, although they are generally even stricter and won't allow using the period either.

I think the period is never an operator in batch, while the comma is, so to prevent abiguous expressions, they don't allow the use of a comma in an identifier.

PS: What kind of bat game are you creating? I created a text adventure once with reasonable succes, but I came to the conclusion that action games have trouble getting the timing right.


As GolezTrol said, , isn't an allowed character for a label.
But it's even more complex, you can view it from two points.
First from the label-view:

The characters of a label will never be expanded, the name of the label stops at one of the characters :+&|<>, and you can't esacpe them neither with quotes nor with carets, as quotes and carets are valid label characters too.
A valid labels can prepended by ANY character (but only one) followed by many out of SPACE,;=TAB

The other view is from the call or goto command:

There are these characters that stops the label <space>, <TAB> and :,;=+ even when the label is in quotes like

call :"myLabel+ignored"
exit /b

:"myLabel
echo It's called by %0

But the output will be :"myLabel+ignored even if the name of the searched label will be only "myLabel.

(<> can also stop the label but not in quotes, they seem to work quite different.

With these two rules it's possible to understand how this works.

@echo off
call :%%%%X+Y%%
echo ---

<;;==;,,:%X<nul=echo hello 
echo Called by %0
exit /b
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号