HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

HELP - Crash bug relating to substrings.

10-22-2002, 11:52 PM#1
Guest
I've almost finished a map that I'm quite proud of, there is only 1 small problem I cannot squash for the life of me.

The map is riddled with dialog-driven commands, I'll use -size as the example here.

typing -size XXX will change the size of the selected unit to XXX percent of its original size.

now this works fine if the format is followed, but if you enter the command without and parameters (e.g. -size ) then warcraft will crash out.

I've determined that its probably doing this since it tries to pull an integer out of the chat string when no integer exists, and therefore gets an outrageous number that overflows the variable assigned to hold it.

So I placed conditions that made sure that the locations targeted by the variable were greater than 0 and less than 700 (no one needs a unit bigger than 700).

the game still crashes if you type -size (with no parameters).

what I'm trying to ask is, how can I make the trigger not run if the space being targeted is not occupied by an integer value between 0 and 700.

Thanks in advance

P.S. all the triggers work beautifully when entered correctly.
10-23-2002, 12:21 AM#2
Guest
If Player 1 enters -size as an exact match then turn off size trigger, wait 5.00 seconds, turn on size trigger
10-23-2002, 01:14 AM#3
ChronOmega
or you could just put a boolean condition

entered string=-size equal to false
10-23-2002, 03:05 AM#4
Guest
ok that solves that, what about for functions that take more than one value?
e.g. -tint XXX XXX XXX.

I would assume typing just -tint XXX or -tint XXX XXX would produce the same error, but since they are varying values, I couldnt do an exact match for any less than 100 conditions per parameter?
10-23-2002, 03:23 AM#5
Guest
Hmm... interesting one there...
10-23-2002, 03:28 AM#6
Guest
sitting around for a few more minutes, the only decision I can come to is to place a confirmatory string at the end of the command. If you have played Arkguil's Tower Defense, this is the logic his gold transfer system uses.

-give 01 04 gold

since the space between the taken variables has to be occupied (if by nothing else, then spaces), theres no chance of the trigger taking an outrageous amount.

if anyone happens to find a more efficient way of doing this (I don't wanna make people type -tint 100 025 100 unit, or something.)
10-23-2002, 03:32 AM#7
ph33rb0
Make it check the length the string could be at minimum and at maximum... and if it's greater or lower than either of those values then don't run the actions :P
10-23-2002, 03:35 AM#8
Guest
I thought of that, but short of using jass, how can I check string length. Unless it's under my nose, I couldn't find it under conditions.
10-24-2002, 11:23 PM#9
Guest
I have been having a similar problem. I have yet to find a condition that stops the game from crashing if an invalid entry is put in.

I've tried just about everything I can think of. I wish people that have gotten it working would post an example of their code. I'd try to check out how they did it, but all the maps I can find are protected :(
10-24-2002, 11:41 PM#10
Guest
Well then, I just found the solution. It is so simple I hit myself on the forehead when I found it.

It isnt that the convert to integer function (or even the substring function, not sure which was crashing it) is getting invalid data, it isnt getting any data at all.

If you refer to string position, say 11, 13, and the string is only 8 bytes long, CRASH!

solution: before you do any substring manipulation, concatenate about 20 spaces on the end of your string, set it to a variable, then work with THAT.

That way, if someone types in your trigger phrase such as -gold or givegold or something, with no parameters, your string is still long enough to be parsed at position 11, etc.


Hope this helps anyone else that may deal with this problem.
10-25-2002, 01:49 AM#11
Newhydra
1. The reason the game crashes is because you're passing a null value to the convert string to int function, and the string to int function doesn't know how to deal with null values so it terminates.

2. The solution is to make sure there is a value at the location you access. If you refer to position 5 in the string, then check does position 5 = a null string. If so, terminate the function call.

3. Check it by comparing the value at position 5(in my example) to the value in the string at position 5000, or any position greater than your max position (IE: people enter a max of 20 chars, compare it to spot 21)

An easier way but would probably require jass to impliment would be to directly compare the value you're passing to convert string to int to null, and return/whatever if it is = to null.