Reversing text

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
atout66
Posts: 266
Joined: Wed Feb 02, 2011 12:31 pm

Reversing text

Post by atout66 » Sat Mar 29, 2014 9:27 pm

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.
Discovering LiveCode Community 6.5.2.

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Reversing text

Post by jmburnod » Sat Mar 29, 2014 9:50 pm

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
https://alternatic.ch

atout66
Posts: 266
Joined: Wed Feb 02, 2011 12:31 pm

Re: Reversing text

Post by atout66 » Sun Mar 30, 2014 9:05 am

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:
Discovering LiveCode Community 6.5.2.

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Reversing text

Post by Klaus » Sun Mar 30, 2014 12:30 pm

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

atout66
Posts: 266
Joined: Wed Feb 02, 2011 12:31 pm

Re: Reversing text

Post by atout66 » Sun Mar 30, 2014 1:22 pm

That's exactly what I misunderstood Klaus :wink:
Discovering LiveCode Community 6.5.2.

Post Reply