Author Topic: GetWords crashes game  (Read 878 times)

I remember this being a problem a long time ago, and sometimes it's not obvious that this causes your game to crash when scripting something.
What causes it to crash is when you try to set the index greater than the amount of words you give it.
Why hasn't Badspot fix this by returning an empty string if the index is greater than the amount of words?
It can get very annoying having to restart Blockland because I set the getWords index one too many.

Code: [Select]
example of a crashing getWords call
==> getWords("0 1 2 3", 4);

Doesn't crash me. Also, getWords takes two arguments.

Correct usage: getWords(string, intStart, intEnt);

Example:

%string = "hello blockland how are you?";

%newString = getWords(%string,2,4);

Doesn't it say "index out of bounds" if you use too high numbers?

I just tried my example and it wasn't crashing me now for some strange reason.
But after messing around, I did echo(getWords("1 2 3 4 5 6 7 8 9", 3, 2)); and it crashed me.
I also started Blockland up again to try it to verify that crashes me, and it does.
What could be causing it to crash?

I just tried my example and it wasn't crashing me now for some strange reason.
But after messing around, I did echo(getWords("1 2 3 4 5 6 7 8 9", 3, 2)); and it crashed me.
I also started Blockland up again to try it to verify that crashes me, and it does.
What could be causing it to crash?
I don't know if this is the reason you're crashing, but when using getWords(); the second argument is the starting word and the last argument is for the word you wish to stop on. getWords(); and getWord(); are also 0 indexed, meaning that getWord(%text, 0); will return the first word.

Using getWords("1 2 3 4 5 6 7 8 9", 3 , 2); will try and give you the 4th word to the 3rd one, but you can't start on the 4th and end on the 3rd - it has to be starting index then the terminating index - the second number should be higher than the first.
« Last Edit: September 03, 2014, 09:07:50 PM by Cruxeis »

I'm always forgetting it's like that and not how many words after index start.
But why doesn't Badspot add a check to see if the end is less then the start, and return an empty string at the beginning of the function?

I just tried my example and it wasn't crashing me now for some strange reason.
But after messing around, I did echo(getWords("1 2 3 4 5 6 7 8 9", 3, 2)); and it crashed me.
I also started Blockland up again to try it to verify that crashes me, and it does.
What could be causing it to crash?
Whatever! Don't do this junk. Tried it. My entire computer screen went black except for the mouse. Had to forcibly restart my computer.

Whatever! Don't do this junk. Tried it. My entire computer screen went black except for the mouse. Had to forcibly restart my computer.
Lmao wow, like I said I forgot it was start and end, not start and how many after.
But never once have I had it make my whole computer screen black.

It's an already known issue. If %startind and %endind are both less than the word count in %string and %endind is less than %startind then getwords(%string, %startind, %endind) instantly crashes blockland.

Example: getwords(0,0,-1); will instantly crash blockland.
« Last Edit: September 03, 2014, 09:29:02 PM by Ipquarx »