Adding to a variable

Posted by Metsuro on Sun 08 Aug 2004 04:32 AM — 11 posts, 33,882 views.

USA #0
Trying to get a trigger to get a varialbe ane have it add to the vairable

Your power level increases by 4 points.

of of this, the levels can go into the millions using commas where they should be in the number order. And i am not really sure how i would even attempt to do this
USA #1
Im not quite sure what youre asking.

SetVariable "Number", Cint(GetVariable("Number"))+%1
will add the variable "Number" to %1 and store it as number.

About commas, Do you mean you can get a number with commas? I believe someone has a script snippet to get rid of them with a bunch of bells and whistles. But, Im not quite sure what youre asking for.


If you want to do that, I believe this should work:
SetVariable "Number", Cint(GetVariable("Number"))+CInt(Replace(%1, ",", ""))

This will remove the commas from a number, before adding it to the variable.
USA #2
yea i meant cause the numbers in the promt can be like 1,000 and 100,100 and stuff like that was just trying to figure out if i could make it add the numbers without the commas. And i tried what you suggest it didn't work
Amended on Sun 08 Aug 2004 06:02 AM by Metsuro
USA #3
You mean without the commas? That replace function should work. Assuming youre using VBscript. Replace is a VBscript function, not a MC one.
USA #4
Error number: -2146828275
Event: Execution of line 1 column 1
Description: Type mismatch: '[string: ""]'
Line in error:

Called by: Immediate execution

Thats what i get
USA #5
Try this:

SetVariable "Number", Cint(GetVariable("Number"))+CInt(Replace("%1", ",", ""))
USA #6
Ok yes not it works wonders thank you greatly
USA #7
Error number: -2146828282
Event: Execution of line 1 column 1
Description: Overflow: 'Cint'
Line in error:

Called by: Immediate execution

Spoke to soon heh. After it ran a few times this poped up
USA #8
It works fine till hitting about 33727 before i get that error
USA #9
32767. Thats the unsigned integer limit.
Youll get that error if you try and CInt something larger than that.

If you wont get a number larger than that (per gain) you could try this:

SetVariable "Number", GetVariable("Number")+CInt(Replace("%1", ",", ""))

That should still work. However, if your %1 is larger than that number... Youll get the error.
USA #10
Try this:
SetVariable "Number", CLng(GetVariable("Number"))+CLng(Replace("%1", ",", ""))

If you have decimals, it will round. But with just integers, you'll have no funny answers.