Detect if text is made of blanks(spacebars) (closed)

t4u

  • Posts: 418
I have a text attribute: text_1
Sometimes text_1 is made of series of blanks.

I cant figure out the way to put proper testing condition for if to tell me if text_1 is made of blanks. Empty text or length text blocks are not working.

Ideas?

« Last Edit: August 02, 2014, 04:36:55 pm by t4u »
USE PICTURES WHEN YOU ASK SOMETHING!
If I helped you be sure to mention it in your game.

Tutorials + downloads:
http://t4upl.blogspot.com/

letmethink

  • *
  • Posts: 2545
There is a block you can find by searing 'has a value' which is a boolean you can use to determine if an attribute has a value.
~Letmethink

PhilIrby

  • Posts: 545
I think a text attribute set to 5 blank spaces will test that it has value, so we will need another way. 
Try
If [trim whitespace from (text_1)] Length> 0   
   If this is false there was nothing  or just spaces in text_1

t4u

  • Posts: 418
My bad. I screwed up. I have forgotten that if you put one blank its length is 1 not 0.
USE PICTURES WHEN YOU ASK SOMETHING!
If I helped you be sure to mention it in your game.

Tutorials + downloads:
http://t4upl.blogspot.com/

Innes

  • *
  • Posts: 1960
If by 'blanks', you mean spaces, then you can test for a string containing only spaces by doing the following:

Replace all the spaces in the original string with nothing (i.e. a real blank), then check the length of the resulting string. If the length of the resulting string is more than zero, then there are characters other than blanks in the original string. If the length of the resulting string is zero, then it means all the characters in the string were spaces.

You will need the [replace text with text in text] block to achieve this.

In the first text box, type a space.
In the second text box, type nothing at all - leave it blank!
In the third box, place the text that you are testing

In the attached image, you can see that I have set the text attribute called "testblanks" to "some text". In the next line, I replace all the spaces in testblanks with a blank character, and I return the length. All you have to do is test the length!

I will reiterate that in the green code block, the box after the word 'replace' has a space in it. The box after the word 'with' has nothing in it - it is completely blank.
Visit www.TheStencylBook.com - the only published book for learning Stencyl.

Justin

  • *
  • Posts: 4716
Here's an alternative to Innes' method, which does exactly what his method does but in different blocks.
For Live Support: Join our discord server and ping me @justin.
I'm most often available between 10am and 10pm Japan time. (GMT+9)

Innes

  • *
  • Posts: 1960
Here's an alternative to Innes' method, which does exactly what his method does but in different blocks.

That's funny, I was convinced  there was a trim function, but I couldn't see it. I thought I was going mad. I think the trim function is more intuitive than replace function; it's easier to read.
Visit www.TheStencylBook.com - the only published book for learning Stencyl.