Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Prim Communication. Am I doing this right?

Cypher Olsen
Registered User
Join date: 7 Aug 2004
Posts: 54
08-27-2004 16:45
I have a prim group that will be a custom vendor object. It has buttons on it to allow you to browse through different items. I'm trying to do this on my own without looking at how others did it, so it's a learning experience. I'm new to LSL, but not to programming.

So, here is how I'm doing it... Will this work?


The MAIN object is setup to listen for messages from the buttons as follows

CODE

link_message(integer sender_num, integer num, string str, key id)
{
//This is triggered when a Child prim (a button) sends a message to this Prim (the main object)

if (str == "Category")
{
if (num == 1)
{
if (Category < Category_limit)
{
Category += 1;
}
else
{
Category = 0;
}
}
else
{
if (Category > 0)
{
Category -= 1;
}
else
{
Category = Category_limit;
}
}
}
else if (str == "Type")
{
if (num == 1)
{
if (Type < Type_limit)
{
Type += 1;
}
else
{
Type = 0;
}
}
else
{
if (Type > 0)
{
Type -= 1;
}
else
{
Type = Type_limit;
}
}
}
else if (str == "Variation")
{
if (num == 1)
{
if (Variation < Variation_limit)
{
Variation += 1;
}
else
{
Variation = 0;
}
}
else
{
if (Variation > 0)
{
Variation -= 1;
}
else
{
Variation = Variation_limit;
}
}

}
else
{
llWhisper(0, "Error in String sent from Child Object to Base Vendor Object.");
}
}//End Link_Message Event



Now, each button is setup to send a message as follows.

CODE

default
{
state_entry()
{
}

touch_end()
{
llMessageLinked(1, 1, "Type", "");
}
}


Basically, I'm using the 'int' and the 'str' from llMessageLinked to determine which button was hit, and I'm changing a global variable as needed.

The global variables are then looked at to determine what the vendor object should be showing.

Am I doing to prim to prim communcation right?
Christopher Omega
Oxymoron
Join date: 28 Mar 2003
Posts: 1,828
Re: Prim Communication. Am I doing this right?
08-27-2004 17:05
From: someone
Originally posted by Cypher Olsen
I'm trying to do this on my own without looking at how others did it, so it's a learning experience.


Ooh, an oxymoron in action ;)
The way you go about learning LSL is looking at other's code, seeing how and why it works, and modifying it. If you really want to learn how to do object to object communication "right" look at what someone else thought was "right" and try to understand how they did it.

By the [uncompilable] code you posted, I can see that you are trying to send messages between two linked prims. Since I dont know what "Category", "Category_limit", "Type", "Type_limit", "Variation" or "Variation_limit" is storing, there's really not much debugging I can help you out with. One thing I did notice though were some of your conditional statements. I can see one in which the assignment operator (=) was used instead of the boolean equivelance operator (==). The LSL compiler is stupid (more correctly, the relics LSL inherited from C are stupid) and doesn't alert you to those kinds of things.

One other thing: Doing things "right" is really a matter of opinion. As long as it works, it works. No one is going to throw tomatoes :)

==Chris
Cypher Olsen
Registered User
Join date: 7 Aug 2004
Posts: 54
08-27-2004 17:19
Chris,

I posted this code from work, so I was not able to compile it in SL. I should of spent a few more minutes on my post to make it clearer however.

First of all, I learn best by writing code on my own, rather than looking at someone elses. After I figure out a way to do it, I'll then go see if someone else generally does it better or faster, and I'll edit my code as needed. This doesn't mean I don't use tutorials and the wiki and all that, I just don't like using others code as my sole learning device. I tend to want to copy what they have rather than write it and learn it myself.

Anyways, Category, Type, Variation, Category_limit, Type_limit, and Variation_limit are all global integer values stored in the script that will be attached to the main vendor prim. They store the current states of the buttons that will exist on the Vendor stall, and they control what model texture will be shown to the buyer.

My main question was whether or not I was sending messages from the child buttons to the main prim correctly.


This code is in the main object, and will respond any time a message is sent to this prim, I believe.

CODE

link_message(integer sender_num, integer num, string str, key id)
{
....
}



This is one sample message that I'm attempting to send to the parent prim. Assuming the parent prim is infact Prim Link Number 1, then am I doing this correctly? Will the child prim send this message to the parent prim, and will it trigger the link_message() event?
CODE

llMessageLinked(1, 1, "Type", "");



If so, then what I'm doing should work. I just wanted to make sure I was on track. I'll be able to test this in SL in a couple hours.

Finally, I edited my post to fix the two equality symbol mishaps. I've been programming in C for years, and I still screw those up a lot on first drafts =)

Christopher Omega
Oxymoron
Join date: 28 Mar 2003
Posts: 1,828
08-27-2004 18:54
Yikes, sorry about sounding so anal :D
If that's all you wanted to debug, then yup, it should work.
Cypher Olsen
Registered User
Join date: 7 Aug 2004
Posts: 54
08-30-2004 11:53
No problem Christopher, my first post wasn't very clear =)

Well, I worked with this over the weekend, and it is indeed working great! It does just what I hoped it would, so my vending machine is coming along nicely.
Wednesday Grimm
Ex Libris
Join date: 9 Jan 2003
Posts: 934
08-30-2004 12:13
Cypher, your baisc idea will work, but it would probably be easier to use link numbers rather than link messages.

When a user clicks on a child prim, and that child prim does not have a script with touch event in it(*), a script in the root prim gets the touch event, and you can use llDetectedLinkNumber to discover which child prim was touched.

(*) Or you get fancy with llPassTouches
_____________________
Sarcasm meter:
0 |-----------------------*-| 10
Rating: Awww Jeeze!
Cypher Olsen
Registered User
Join date: 7 Aug 2004
Posts: 54
08-31-2004 10:39
From: someone

When a user clicks on a child prim, and that child prim does not have a script with touch event in it(*), a script in the root prim gets the touch event, and you can use llDetectedLinkNumber to discover which child prim was touched.


Oh.. Well... That's cool =)

That will certainly make it even easier to do. I don't have to create a separate touch script for every child object this way. I'll work with that.

Thanks Wednesday.