Jump to content

Question about llDialog in relation to events outside of Listen


Lance Shadow
 Share

You are about to reply to a thread that has been inactive for 3299 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Hi all, I'm attempting to make an object that has an adjustable integer via dialog menu and with that I'm all set, but the thing is I need to then get that adjusted integer to apply to events other than just Listen(), and since variables that aren't global don't apply to other events, how do I uh, make it global? Sorry if it's a noob question, I'm completely self taught thus far.

for example

listen(blahblahetcetc)
{
if (msg == ".5")
integer gap = (integer)msg;
}

link_message(blahblahX2)
{
//I need the heard gap integer to apply in this event

 

Link to comment
Share on other sites

It just occured to me to have one of my button scripts listen for the message and then send it to the main script using llMessageLinked in order to get it applied to the link_message event, which I think would work fine. But that seems like a workaround and I'm still curious if there's a more direct way to do this, for future reference if nothing else.

Link to comment
Share on other sites


Lankarion Lock wrote:

Hi all, I'm attempting to make an object that has an adjustable integer via dialog menu and with that I'm all set, but the thing is I need to then get that adjusted integer to apply to events other than just Listen(), and since variables that aren't global don't apply to other events, how do I uh, make it global? Sorry if it's a noob question, I'm completely self taught thus far.

for example
Listen(blahblahetcetc){if (msg == ".5")integer gap = (integer)msg; // gap is a variable local to the listen event}link_message(blahblahX2){//I need the heard gap integer to apply in this event

 

Declare the variable before the first scope is opened, and it'll be global to everything...

integer gap;    // gap is global to everything default{     listen()     {          gap = integer(msg); // so gap is available in this event     }      link_message()     {          llOwnerSay((string)gap); // and in this one     }}

 

http://wiki.secondlife.com/wiki/LSL_101/Global_vs_Local_Variables 

Link to comment
Share on other sites


Lankarion Lock wrote:

Oh... *embarrased face* 

I had integer gap = 1; as global to make like a "default" gap, but yeah that's not necessary. If I hadn't set it up like that I probably wouldn't even have looked twice it would have just worked! D:

You can set gap equal to 1 at the top if you want a default value.

Link to comment
Share on other sites

Okay well I guess the problem I thought I had wasn't even the problem at all. I had that all set up fine it seems. But at least I gained a little better understanding of global vs local variables. I just assumed I had to "declare" variables in order to use them in an event and then whatever I defined them as in the event didn't apply anymore in following events. I didn't realize that info was then applied to the global variable until changed.

Link to comment
Share on other sites

Okay, actually, I think you misunderstood my original question. I wasn't just asking how to make the variable name global, I was asking how to use the number applied to that variable in one event still valid in another event. If I tell gap to equal .5 in listen, it is no longer .5 within the link_message event, it has reset to 0 as I initially thought it would. I tested this with llSay in both listen() and link_message().

I wasn't asking how to simply write "integer gap;" in the global section >_< Sorry if I wasn't clear enough.

Listen(blahblahetcetc){if (msg == ".5")integer gap = (integer)msg; // gap is a variable local to the listen event}link_message(blahblahX2){//I need gap to STILL EQUAL .5 or 1 or 2 or WHATEVER the dialog menu msg told it to equal in Listen()
Link to comment
Share on other sites


Lankarion Lock wrote:

Okay, actually, I think you misunderstood my original question. I wasn't just asking how to make the variable name global, I was asking how to use the number applied to that variable in one event still valid in another event. If I tell gap to equal .5 in listen, it is no longer .5 within the link_message event, it has reset to 0 as I initially thought it would. I tested this with llSay in both listen() and link_message().

I wasn't asking how to simply write "integer gap;" in the global section >_< Sorry if I wasn't clear enough.
Listen(blahblahetcetc){if (msg == ".5")integer gap = (integer)msg; // gap is a variable local to the listen event}link_message(blahblahX2){//I need gap to STILL EQUAL .5 or 1 or 2 or WHATEVER the dialog menu msg told it to equal in Listen()

Your "gap" variable is local to the listen handler. Any "gap" variable you declare in the link_message handler is a completely different local variable. I gave you an example of how to create a global variable, you'll have to follow that example.

Here's a script that demonstrates the persistence of a global variable across events. Drop it in a prim then start touching it, you'll see count being incremented by the timer event, touching it will display the count...

integer gap = 0;default{    state_entry()    {        llSetTimerEvent(1);    }    timer()    {        gap++;    }        touch_start(integer total_number)    {        llOwnerSay((string)gap);    }}

Until you declare "gap" above default, you're not going to get the behavior you desire. If you have done that, then your code is zeroing out "gap" somewhere else.

Link to comment
Share on other sites

integer gap;default{    touch_start(integer total_number)    {        integer gap = 5;        llSay(0, "gap is equal to " + (string)gap);    }        changed(integer change)    {        llSay(0, "gap is equal to " + (string)gap);    }}

This script illustrates what I'm talking about. gap is declared globally. Touch it and it will tell you gap is equal to 5. Drop a prim in it to trigger the changed event and it will then proceed to tell you gap is equal to 0.

Link to comment
Share on other sites


Lankarion Lock wrote:

6 buttons, one small script in each. Do you mean one script total should be able to manage all 6 buttons?

Yes, especially if your using llDialog where each would need a listener, but even if your using prims, or face touches for the buttons, one script should be all you need for all the buttons.  If your main script is the only other script you have then it might be possible to just combine them all in to one script, depending on what the main scrip dose.

Link to comment
Share on other sites

Well thanks guys, I'll definitely fiddle around with that.

One of the things that my buttons do is shift the prim over a given amount of space (dictated by a given amount of space + gap) and in a certain direction (dictated by which button was touched).

llSetPos(llGetPos() + <0,0,.5853+gap>);

it works as long as the user doesn't rotate the prim. Well, it still "works", but the arrows on the buttons no longer point the direction that the object actually moves. Manipulating vectors is probably the thing I've had the hardest time understanding.

I know the reason WHY it does this is because I have each button set to move along a specific axis, I just don't know if there's a way to get it to recognize that the object has been rotated without adding in a long list of if (llGetRot ==) checks >_>

Link to comment
Share on other sites


Lankarion Lock wrote:

integer gap;default{    touch_start(integer total_number)    {        integer gap = 5;        llSay(0, "gap is equal to " + (string)gap);    }        changed(integer change)    {        llSay(0, "gap is equal to " + (string)gap);    }}

This script illustrates what I'm talking about. gap is declared globally. Touch it and it will tell you gap is equal to 5. Drop a prim in it to trigger the changed event and it will then proceed to tell you gap is equal to 0.

I've struck through your problem in the code above.

You've declared a global variable "gap" at the top of the script, but then you've declared a local variable "gap" in the touch_start() event. Whenever you prefix a variable name by a type declaration, you are declaring a new variable with that name, regardless of where you do it.

So, in touch_start(), the local gap displaces the global gap. The changed() event uses the global gap, which hasn't been assigned a value and is therefore zero.

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 3299 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...