string losing spaces?

BlitzMax Forums/BlitzMax Beginners Area/string losing spaces?

Pete Carter(Posted 2008) [#1]
hi in my point and click game i have two strings that display sentances when you hover the mouse over hot spots.

one is called context the other is called text and for example it would be something like this.

Context = " Look at "
text = "sign"

display writes "look at sign"

after i pick up a few items my string loses its spaces and then everything looks like this.

"Lookat sign"

ive check every place i assign the varibles values and im always adding spaces i dont get it?


tonyg(Posted 2008) [#2]
ive check every place i assign the varibles values and im always adding spaces i dont get it?

I am guessing you missed one.
What you need to do is create a function called concatenate_strings.
The function should :
a) Accept two strings as arguments.
b) Add them together with a space in between
c) Write the two original strings plus the new string to debulog
d) Return the new string.
You then need to go through your code replacing any variable assign with a string without a space on the end and adding the strings using this function.
If you get an error and there isn't a debug message then it's likely you have missed one.


Pete Carter(Posted 2008) [#3]
No i didnt miss one. I thought i had but i used stops all the way though my code and for some reason the string becomes "look at~t" about half way though my code. but when i draw it to the screen it shows "lookat" with on its own is strange.

Ive got round the problem by putting the space in the second string and removing it from the first. it worked but id still like to know why my first string got messed up if it has spaces.

Pete


tonyg(Posted 2008) [#4]
Options are :
a) Its a bug... unlikely
b) it's a coding error.
For b) it'll be difficult to say without the code.
Do you have a function which takes two strings, adds them together and returns the result with a space in between or do you do it individually each time?
It really helps debugging if you have smalle units of code split into functions.


GfK(Posted 2008) [#5]
Trim() will remove spaces from either end of strings, so if you're using that anywhere that's what I'd look at first.

Also, if you're using Replace() anywhere, check that too.


TomToad(Posted 2008) [#6]
I noticed in your example that you have a space before Look. Could it be you are later using Left(), Right(), [..n], or [n..] somewhere on the string and removing the last space, thinking the original string is 8 characters long when it is really 9?


Pete Carter(Posted 2008) [#7]
It maybe my code, but its just seams odd that it some how ends up in the debug as "lookat~t"? anyway, i think ive wasted everyones time here enough, i rewrite that section of code and it i still have the problem ill get back to you. thanks for your advice.