Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

llHttpRequest and various expressions after

Anno Reina
Registered User
Join date: 5 Sep 2009
Posts: 2
11-26-2009 00:24
Hi,

I need to do a script, which is going to take information somewhere on the internet, and get them back in sl. That's ok, I succeed to do that. But just after I want to use an llMapDestination... and the problem is that the llMapDestination appear while the treatment of the llHttpRequest isn't done (and my variables not loaded of course).

Let me do a quick example:
CODE

key reqid;
string sim ="";

default
{
touch_start(integer total_number)
{
reqid = llHTTPRequest("http://example.com:9999/test", [HTTP_METHOD,"GET"], "" );
llMapDestination(sim,<128,128,0>,<1,0,0>); //1
}

http_response(key id, integer status, list meta, string body) {
sim=body; //2
}
}


So the problem is that the variable sim isn't loaded when my script arrive to llMapDestination... I try with a llSleep before the llMapDestination, but no way.

If someone get a cool solution please.... thanks a lot :)
Pale Spectre
Registered User
Join date: 2 Sep 2005
Posts: 586
11-26-2009 01:43
Try moving the llMapDestination function from the touch_start event into the http_response event.

LSL is an event driven language which means you have think in an event driven way. So, in this case, the event that needs to trigger your map destination is the response from the HTTP request and not the touch.

BTW, llSleep will simply suspend all events from occurring, including the HTTP response.
_____________________
Viktoria Dovgal
Join date: 29 Jul 2007
Posts: 3,593
11-26-2009 02:01
llMapDestination only works inside touch* events unless you are wearing the object.

A two touch approach is the usual workaround for this restriction.

CODE

key reqid;
string sim ="";

key last_toucher;
float timeout = 10.0;

default
{
touch_start(integer total_number)
{
if (last_toucher) {
if (llDetectedKey(0) == last_toucher) {
llSetTimerEvent(0.0);
if (sim != "")
llMapDestination(sim,<128,128,0>,<1,0,0>); //1
last_toucher = "";
sim = "";
}
}
else {
last_toucher = llDetectedKey(0);
reqid = llHTTPRequest("http://example.com:9999/test", [HTTP_METHOD,"GET"], "" );
}
}

http_response(key id, integer status, list meta, string body) {
sim=body; //2
if (last_toucher) {
llInstantMessage (last_toucher, "Touch me again for a map to your destination.");
llSetTimerEvent(timeout);
}
}

timer() {
llSetTimerEvent(0.0);
last_toucher = "";
sim = "";
}
}


As an alternative, you might skip llMapDestination, sent the SLurl to chat, and ask the user to Ctrl-H and click the SLurl.
Anno Reina
Registered User
Join date: 5 Sep 2009
Posts: 2
11-26-2009 02:05
Yes Viktoria, I notice the problem for the llMapDestination.

I'll try your script tonight, and will do a return here. Thanks a lot!
Haravikk Mistral
Registered User
Join date: 8 Oct 2005
Posts: 2,482
11-26-2009 04:00
How often is the return value of your site likely to change? It may be possible to fetch the data before the touch-event occurs if you can share a little bit more about what you're trying to do.

For example, if the sim-name is dependant on where you are then you could perform the lookup using the following:
CODE
changed(integer x) {
if (x & CHANGED_REGION) {
// Send your HTTP request here
}
}


Also, it's not true that llMapDestination() only works in the touch-event, however the request will be sent to the object owner if used outside this event. If you are using llMapDestination() for a HUD then you can use it pretty much anywhere in your code, it's only if the object is rezzed in-world where it may be used by others that you will need to be wary of where the function is called.
_____________________
Computer (Mac Pro):
2 x Quad Core 3.2ghz Xeon
10gb DDR2 800mhz FB-DIMMS
4 x 750gb, 32mb cache hard-drives (RAID-0/striped)
NVidia GeForce 8800GT (512mb)
Viktoria Dovgal
Join date: 29 Jul 2007
Posts: 3,593
11-26-2009 05:16
From: Haravikk Mistral
Also, it's not true that llMapDestination() only works in the touch-event,

No. Touch only is the intended behavior for non-attached objects.

From: someone
however the request will be sent to the object owner if used outside this event.

There was a bug that did do something like this, SVC-1795, but it was fixed several months ago. If you can still reproduce this bug it needs a new ping to Andrew.

Reference: