// Create a message to send LLMessageSystem message; message.newMessage("hello"); // Add a string parameter using addStringFast message.addStringFast("name", "Alice"); // Send the message message.sendReliable(gAgent.getRegion()->getHost());
// Handle a message received with a string parameter void handleMessage(LLMessageSystem* message, void* userdata) { std::string name; // Get the value of the "name" string parameter using getString if (message->getString("name", name)) { // Do something with the name std::cout << "Received name: " << name << std::endl; } } // Register a message handler for the "hello" message type void registerMessageHandler() { LLMessageSystem::registerMessageFunction( "hello", handleMessage, nullptr); }In this example, we define a message handler function handleMessage that gets called when a message of type "hello" is received. Inside the handler function, we use getString to extract the value of the "name" parameter from the message and output it to the console. Note that we don't use addStringFast here since we are receiving a message, not sending one. Package library: Second Life Viewer SDK