Author Topic: -= doesn't work  (Read 749 times)

Offline DavidW

  • Planewalker
  • *****
  • Posts: 316
-= doesn't work
« on: June 19, 2022, 04:24:44 PM »
OK, this one surprised me. var1 -= var2 is supposed to abbreviate var1=var1 - var2. Unless I am seriously confused, it doesn't do anything.

e.g.

Code: [Select]
OUTER_SET x=10
OUTER_SET x-=2
PRINT "%x%"
Should be 8, actually is 10.

Offline Argent77

  • Planewalker
  • *****
  • Posts: 187
Re: -= doesn't work
« Reply #1 on: June 19, 2022, 04:44:03 PM »
It looks like whitespace is important. This code works as expected:
Code: [Select]
OUTER_SET x = 10
OUTER_SET x -= 2
PRINT "%x%"  // output: 8

Without whitespace around the operator, WeiDU treats "x-" as the variable name that has been assigned the value 2.
Code: [Select]
OUTER_SET x-=2
PRINT "%x-%"  // output: 2

Offline Wisp

  • Moderator
  • Planewalker
  • *****
  • Posts: 1176
Re: -= doesn't work
« Reply #2 on: June 20, 2022, 09:48:32 AM »
It comes down to ambiguous grammar. Quote the variable name and the code works, or include whitespace, because then the ambiguity is gone.
 

Offline DavidW

  • Planewalker
  • *****
  • Posts: 316
Re: -= doesn't work
« Reply #3 on: June 20, 2022, 09:37:21 PM »
Ah. OK, that makes sense. Just a special case of - being a pain. Sorry for false alarm.

 

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Name: Email:
Verification:
Type the letters shown in the picture
Listen to the letters / Request another image
Type the letters shown in the picture:
What color is grass?:
What is the seventh word in this sentence?:
What is five minus two (use the full word)?: