Page 1 of 1

No CR in Livecode server script

Posted: Tue Apr 11, 2017 5:07 pm
by raugert
I'm trying to use Livecode server instead of PHP but can't get the Carriage Return to work...

<?lc
put URL "file:/applications/mamp/htdocs/scroller/sse/play" into play
put "event: " & "event1" & CR & "data: " & play into ptext
put ptext
?>

This outputs : event: event1 data: play

instead of:

event: event1
data: play

Re: No CR in Livecode server script

Posted: Tue Apr 11, 2017 6:03 pm
by Klaus
Hi raugert,

1. welcome to the forum! :D

2. in a server script "put" will output HTML and HTML does not know what CR means!
Do this:
<?lc
put URL "file:/applications/mamp/htdocs/scroller/sse/play" into play
put "event: " & "event1" & "<br>" & "data: " & play into ptext
put ptext
?>
Important hint:
"play" is a reserved word, so use another name for the variable or this may cause some inconvenience!

Best

Klaus

Re: No CR in Livecode server script

Posted: Tue Apr 11, 2017 9:02 pm
by raugert
Thanks for the quick response Klaus.

I think I need to change my thinking to use Livecode server for server sent events (sse). I guess it's not like PHP "echo" and HTML "addEventListener" ?

Here's what I am currently doing:
1. I have an HTML file that scrolls a bottom line 'ticker" for television.
2. I have made a Livecode app to input the data (text size, font, text elements, speed, etc.) . Each element is sent to a separate file. This works well so far.
3. I then read these files with jQuery AJAX calls to put the variables into <div> and CSS
4. I then use a simple PHP "get_file_contents" and "echo" for getting the control codes like (play, pause, reset) and then use addEventListener in my HTML to execute the functions . This also works OK

BUT.. I would like to use more Livecode to accomplish this rather than PHP. It seems like Livecode server is more HTML / text based ?

I think I might be going about this the wrong way. Sorry for so many questions. I haven't received the books yet. :cry:

Hope this makes some sense :?

thanks for your help,

Re: No CR in Livecode server script

Posted: Tue Apr 11, 2017 9:37 pm
by Klaus
Hi raugert,

sorry, I have very little knowledge about all this web-stuff, so no idea what:
PHP "echo" and HTML "addEventListener"
actually is or does.
It seems like Livecode server is more HTML / text based
Not really, it outputs HTML (just like PHP :D ) but can do a lot more of course.
But, see above... :oops:


Best

Klaus

Re: No CR in Livecode server script

Posted: Tue Apr 11, 2017 9:53 pm
by SparkOut
Think of LiveCode Server as exactly like php and you will not be far wrong.

Code: Select all

<?lc put "Some plain text" ?> 
is equivalent to

Code: Select all

<?php echo "Some plain text"; ?>
Just the same as

Code: Select all

<?lc put "<div>Some html text<br />split over two lines</div>" ?> 
is equivalent to

Code: Select all

<?php echo "<div>Some html text<br />split over two lines</div>" ?>
and

Code: Select all

<?lc put "Some variable text" into tVar
put "<div>" & tVar & "</div>" ?> 
is equivalent to

Code: Select all

<?php $var = "Some variable text";
echo "<div>".$var."</div>" ?>
Where you might find some confusion is in php's interpretation of \n as a linefeed within the php code, but I don't think it renders like "<br />" would on the page anyway. Also php can interpret variables within the string literal as well as concatentating, as above. LC has to concatenate always.

Re: No CR in Livecode server script

Posted: Thu Apr 13, 2017 2:58 pm
by Mariasole
Wow!
SparkOut you are a Rosetta Stone of coding! :D
very very interesting!!!

Mariasole
( ^..^)οΎ‰