How do openXXX messages work on server?

Are you using LiveCode to create server scripts or CGIs?

Moderators: heatherlaine, Klaus, FourthWorld, robinmiller, kevinmiller

Post Reply
edgore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 197
Joined: Wed Jun 14, 2006 8:40 pm

How do openXXX messages work on server?

Post by edgore » Thu Jul 24, 2014 5:14 pm

I noticed that the openStack & openCard messages show in the dictionary as supported on server, but I am not sure what they are supposed to do there. My assumption was that since server doesn't have stacks or cards that one (maybe both?) of these message might get sent when a script was opened.

This would have been handy since it would make it much easier to develop on the desktop (where there is a debugger) and port to server. When developing on the desktop I could put all of the server-specific stuff into an openStack or openCard handler enclosed by an 'if the environment is "Server"' condition.

However, it seems that things don't work like that at all. The following script:

Code: Select all

<?lc
   on openStack
   put "Got an openStack Message" & return
   end openStack
   on openCard
   put "Got an openCard Message" & return
   end openCard
put "finished"
?>
outputs just "finished". Clearly neither message gets sent. So...how are these supported in server? Also, is there a message that does get sent when a server script is opened that I could use like this?


Edit - Also tried the same with the startUp message - it also doesn't do anything
Last edited by edgore on Thu Jul 24, 2014 7:53 pm, edited 1 time in total.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6024
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: How do openXXX messages work on server?

Post by FourthWorld » Thu Jul 24, 2014 6:43 pm

System messages like openCard are part of the GUI event loop, which is not in play when running from the command line as with LiveCode Server.

Instead, you can simply put your LiveCode commands within your LC tags to execute - see the examples here in the LiveCode Server Guide:
http://livecode.com/developers/guides/server/
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

edgore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 197
Joined: Wed Jun 14, 2006 8:40 pm

Re: How do openXXX messages work on server?

Post by edgore » Thu Jul 24, 2014 7:48 pm

Oh yeah, I know that. Mainly I was just wondering why these are marked as supported on server when I can't find any use for them, or any effect they have.

Also, I am always trying to find any way that I can write code on the desktop (with a debugger), have it work there, and paste it directly over to a text file between livecode tags without any fiddling to change it to work on server.

Seeing that opencard/stack/startup list as supported in server raised the hope I would be able to get away with a script like:

Code: Select all

on openStack --or openCard, or startUp
  if environment is server 
     do server specific stuff
  end if
  if environment is desktop
   do desktop specific stuff
  end if
  do environment independent stuff
end openstack

function myfunction
  do function stuff
end function
If openStack actually did anything on server that script could potentially be copied an pasted right between livecode tags with no edits. As it is I have to go in and remove the on and end for whatever handler is enclosing the stuff in the first section that makes it work with desktop (usually an on mouseUp these days).

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1681
Joined: Sat Feb 28, 2009 11:49 pm

Re: How do openXXX messages work on server?

Post by sturgis » Fri Oct 03, 2014 7:21 pm

The opencard openstack messages are supported because you can "go stack..." from a script, at which point the stack you go to executes its opencard/stack/whatever handlers. You can also library a stack which means that you can do much of your coding in the LC ide, save the library stack to wherever your server is, and use it as if it was a regular old library. Which it is. (start using ....)

Post Reply

Return to “CGIs and the Server”