User:ELQ Homewood

From Second Life Wiki
Jump to: navigation, search
   I'm ELQ Homewood from North Carolina, USA. I'm a scripter specializing in in-world club items,
professional tools and club/business systems.
I speak English and script in LSL. I'm a web developer and application programmer with a focus on
desktop-web-vw integration. My in-world store is H&S Originals at [1].

Simple HTTP-In from your Desktop! Here's a tutorial that will help show how a simple html form can be used, straight from the desktop, to communicate with your LSL scripts ;o)

  • First, you'll need a prim.

  • In this prim use this script - alter it how you want, it's pretty simple and it's mostly the script for http-in we've all seen a hundred times.
  • <lsl>key requestURL;

    default {

       touch_start(integer num_detected) {
           requestURL = llRequestURL();     // Request that an URL be assigned to me.
       }
        http_request(key id, string method, string body) {
    
           if ((method == URL_REQUEST_GRANTED) && (id == requestURL)) {
               // An URL has been assigned to me.
               llOwnerSay(body);
               llOwnerSay("Copy and paste the above url into your html form action.");
           }
           
           else if ((method == URL_REQUEST_DENIED) &&(id == requestURL)) {
               // I could not obtain a URL
               llOwnerSay("ERROR: " + body);
               requestURL = NULL_KEY;
           }
    
           else if (method == "POST") {
              llOwnerSay(body);
              
              llHTTPResponse(id,200,"Baddabean!");
           }
           
           else {
               // An incoming message has come in using a method that has not been anticipated.
               llHTTPResponse(id,405,"Unsupported Method");
           }
       }
       //use this if you have a way to update the prim url, such as an offworld file or db
       //changed(integer change) {
           //if(change & CHANGED_REGION_START) llResetScript();   
       //}
    

    }</lsl>

  • As you can see, when it receives a POST, it will llOwnerSay the posted message to you and then respond with 'Baddabean!' Now, it's time to minimize SL and open Notepad or whatever plain text writer you have.

  • In your text file, you're going to create an html page like so:
  • <html4strict><html> <head><title>Testing 1-2-3</title></head> <body> <form name="frmTest" method="POST" action=""> Ask this inworld: <input type="text" size="40" name="question" value="What bean won't give you gas?" />
    <input type="submit" value="Ask"></form> </body> </html> </html4strict>

  • Here, you can see it's a simple html form. First thing you'll notice is that the action is empty in the form tag. Switch back to SL, and touch your prim. You should get the prim's URL in chat. Copy the URL from chat history, jump back over to your text file and paste the URL between the quotation marks for the form action tag. Save your text file with an html extension.

  • Now, just open your new html page in your browser (double click for most) and press the submit button. You should immediately go to a page with the response 'Baddabean!' or whatever you made your script say. Jump over to SL and look in chat - you'll see the question sent from your desktop!