Page 1 of 1

Reversing text

Posted: Sat Mar 29, 2014 9:27 pm
by atout66
Hi to all,

There is a lesson called "Reversing text" in the LiveCode developers area. It's here: http://lessons.runrev.com/s/lessons/m/2 ... rsing-text
When I follow this lesson, I don't get at all the expected result, and I don't understand why... The reverse text isn't done.
I have the fields "Reversed Text" and "Answer", and a button with the code from the lesson:

Code: Select all

on mouseUp
   get reversed("A man, a canal, Panama")
   put reversed(it) into field "Reversed Text"
   answer reversed(field "Answer")
end mouseUp
And the function reversed() is in the card:

Code: Select all

function reversed pString
    local tReversedString
    repeat with tChar = the length of pString down to 1
        put char tChar of pString after tReversedString
    end repeat    
    return tReversedString
end reversed
Are they some of you who have done this tutorial with sucess ?

Note: I use LC 6.5.2

Thanks in advance.

Re: Reversing text

Posted: Sat Mar 29, 2014 9:50 pm
by jmburnod
Hi Atout66,

Yes reversed function works well but your script reverse the string two times.

Code: Select all

on mouseUp
   get reversed("A man, a canal, Panama") -- you put the reversed string in it
-- put reversed(it) into field "Reversed Text" -- you reverse it 
put it into field "Reversed Text"
 --  answer reversed(field "Answer")
end mouseUp
Sorry I don't understand

Code: Select all

answer reversed(field "Answer")
I guess

Code: Select all

on mouseUp
 ask "String to reverse"
   if it <> empty then
      answer reversed(it)
   end if
end mouseUp
Best regards
Jean-Marc

Re: Reversing text

Posted: Sun Mar 30, 2014 9:05 am
by atout66
Ah ! you're right Jean-Marc. I was confused with this script from the lesson. I understand why now :shock:

Still don't guess what the teacher meant with:

Code: Select all

put reversed(it) into field "Reversed Text"
answer reversed(field "Answer")
instead of

Code: Select all

put IT into field "Reversed Text"
only...

Anyway, thanks for your help :wink:

Re: Reversing text

Posted: Sun Mar 30, 2014 12:30 pm
by Klaus
Hi guys,

at the top of that namely lesson, like in many other lessons,
the author just shows a couple of exmples of the usage of his function:
...
get reversed("A man, a canal, Panama")
put reversed(it) into field "Reversed Text"
answer reversed(field "Answer")
...
They do not neccessarily have any further meaning 8)


Best

Klaus

Re: Reversing text

Posted: Sun Mar 30, 2014 1:22 pm
by atout66
That's exactly what I misunderstood Klaus :wink: