Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

HTTPRequest and State Change

Lief Rush
Registered User
Join date: 15 Dec 2006
Posts: 18
11-15-2007 07:11
Greetings all,

Been trying to get this script working for over 2 hours.. I wonder if someone can take a peek and see what I am doing wrong.

It makes a simple call to the web and gets back a simple reply of a color. I then want it to, based on the reply, enter the state associated with that color. I added a place to have the script echo the message from the server, and I am getting back the right data, but I am not understanding how to enter a new state and keep the data from the server intact, as I am never getting any of the entering state messages or for that matter the leaving default state message either so I suspect my 'if' statements are dying silently.

I hope I made sense! Here is the script:
BEGIN LSL
______________________

key http_request_id;
string URL = "http://www.somewebpagesomewhere/pickcolor.php";



default
{
state_entry(){}

on_rez (integer something)
{
http_request_id = llHTTPRequest(URL, [], "";);
}

http_response(key request_id, integer status, list metadata, string body)
{
llSay(0,body);



if (body == "RED";)
{
state RED;
}

if (body == "GREEN";)
{
state GREEN;
}
if (body == "BLUE";)
{
state BLUE;
}

}
state_exit()
{
llSay(0,"Leaving Default state";);
}
}

state RED
{


state_entry()
{
llSay(0,"Entering Red State";);
}state_exit()
{
llSay(0,"Leaving Red state";);
}
}


state GREEN
{
state_entry()
{
llSay(0,"Entering Green State";);
}state_exit()
{
llSay(0,"Leaving Green state";);
}
}

state BLUE
{
state_entry()
{
llSay(0,"Entering Blue State";);
}
state_exit()
{
llSay(0,"Leaving Blue state";);
}
}


END LSL



Here is the very simple PHP file that sends back the info.

BEGIN PHP
-----------------------

<?php

{
echo "BLUE";
}
?>

__________________
END PHP


Sorry to be such a noob!!TIA!!
Yumi Murakami
DoIt!AttachTheEarOfACat!
Join date: 27 Sep 2005
Posts: 6,860
11-15-2007 07:22
Try replacing llSay(0,body); with llSay(0,"<" + body " + ">";); so you can make sure there's no extra whitespace or carriage returns or similar nastiness sneaking in.
Haruki Watanabe
llSLCrash(void);
Join date: 28 Mar 2007
Posts: 434
11-15-2007 07:27
Actually, it all looks fine to me...

There might be a small error in the PHP-File though. If you happen to have a space after the closing php-tag (?>;) this would be sent to SL as well.

So you might end up with something like «RED_» (where the _ represents the space).

try to add the following to the line where you output the HTTP-body:

llSay(0, "*" + body + "*";);

That way, you'll see whether there are some spaces either at the beginning or at the end of the HTTP-body...

HTH
Lief Rush
Registered User
Join date: 15 Dec 2006
Posts: 18
omg.. ur both right on point...
11-15-2007 07:35
My server is sending back a blank space at the end of the echo..

OMG...TY TY TY!!

I guess now I figure out how to parse the reponse to remove the space? (my quick test workaround was to add a space after my test responses in the script, but thats not really a very elegant solution) I did fix the space you so masterfully detected in the php script as well.

Again.. TY TY TY BOTH!!