ID:261175
 
mob
Star_Ships
Black1
var
global
basecodenum = 0
icon='Star Ships.dmi'
name = "Black"
New()
var/newcodenum = basecodenum += 1 // This is where the error is!
var/codenum = newcodenum
basecodenum += 1
src.suffix = codenum


This is a simple codenumber-giving proc that I wrote. However, it does not generate a code number. It generates an error.

loading Space Adventure.dme
Chars.dm:15:error: +=: expected end of statement
Chars.dm:15:error: missing left-hand argument to +=.

Space Adventure.dmb - 3 errors, 0 warnings


First of all, it dosn't show 3 errors. Second of all, there is already a left hand arguement to +=, isn't there?

I do not understand this. :(
ok im gonna attempt to help

the line var/newcodenum = basecodenum += 1

try changing it to this...

var/newcodenum = basecodenum+1
if i am correct. this should eliminate the other 2.. which may be spawned due to the first error.. i get that alott. all other codes beneath this may be affected.. but easily fixed. if the top is fixed... soo. try this and show results :-D ill try to help if it doesnt work.
In response to SonVegitto
Excellent, thanks. I'll remember that.
In response to Lord of Water
no problem.. glad to help.. wow ive helped alott of people!

i deserve a cookie =D
In response to Lord of Water
I believe the left hand argument in such an expression must be constant. Which will explain why

a = b += c

does not work because that translates into

a = b = b + c (ie b is no longer a constant because you are changing it)

however

a = b + c

will work because you arent changing the value of b, you are simply adding the total of b+c to the value a.
My knowledge of general code is not that great it's just an...err...uneducated guess. Anyone care to proove me wrong/right I would be more to happy to hear if I have it figured out or not.

Alathon
In response to Alathon
Yer to late on yer que :-D i already tole him.. MY COOKIE! no one gets my cookie.. mmmmmm cookie
In response to SonVegitto
SonVegitto wrote:
Yer to late on yer que :-D i already tole him.. MY COOKIE! no one gets my cookie.. mmmmmm cookie

My question was about the general mechanics of the += operator, it was simply a clarification(out of my knowledge) of WHY it didnt work. If you want cookies so much go buy some..hungry beggar

Alathon
In response to Alathon
Fine.. if you wanna be uptight like that ill split it you greedy-noble. :-P
In response to Alathon
Alathon wrote:
I believe the left hand argument in such an expression must be constant. Which will explain why

a = b += c

does not work because that translates into

a = b = b + c (ie b is no longer a constant because you are changing it)

however

a = b + c

will work because you arent changing the value of b, you are simply adding the total of b+c to the value a.
My knowledge of general code is not that great it's just an...err...uneducated guess. Anyone care to proove me wrong/right I would be more to happy to hear if I have it figured out or not.

Alathon

Actually I believe the problem is that BYOND doesn't handle compound assignments well. Probably something with the compiler. An expression like a=b=c will make the DM compiler strangle you. I haven't tested to see if a=(b=c) would work, but I suspect it would. BYOND is smart about lots of other operators used in C-like ways, so I think it's just a matter of the assignment operators not working right.

My suspicion is that in DM, assignment operators don't associate right-to-left as they do in C. Thus, a=b=c is interpreted as (a=b)=c. If the result of a=b is interpreted as an Rvalue instead of an Lvalue (in C, an Rvalue is a constant, and Lvalue goes with a variable), then BYOND would think you're assigning constant=constant, and pitch you an error. However, if it's thinking a=b=c is (a=b)=c, the error is preferable to the unfortunate result of either a=c or a=b,b=c which would be hard to debug.

Lummox JR
In response to Lummox JR
Ah, I see. I never used the operator like that in C (then again I havent done much C, side twinking and adding a few classes / balancing / fight code to a MUD) so I wasnt aware that it was possible in C, might have come up with an even weirder answer then hehe, so all is good. Thanks for clearing that up, might be usefull someday now I know you can do it in C

Alathon
In response to Lummox JR
Actually I believe the problem is that BYOND doesn't handle compound assignments well. Probably something with the compiler. An expression like a=b=c will make the DM compiler strangle you.

That's by design, though it does have the side-effects to which you alluded.

I don't think "a = (b = c)" works either.