Jump to content

Roleplay Hud


MarkBWalker
 Share

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

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

Recommended Posts

I'm a student in coding, and I have a goal in mind.

I'd like to create a RP HUD system, but here is my goal.

I'd like to put out food items, water items, and healing items throughout a region.

Then, a player can click those items to consume them, and they disappear. Only to reappear again five minutes later. Or, there is a lockout timer so they can't be clicked again for five minutes.

And while doing this, the player wears a HUD that has buttons for FOOD, WATER, and HEALTH to display meters that express how full each title is.

Clicking the item is consumed and refills the HUD's levels.

How can this script be written?

PS. Since I am a student in coding, any scripts taught or provided will be studied and duplicated for additional practice.

 

 

Edited by MarkBWalker
Link to comment
Share on other sites

There's potentially a lot to unpack there, but fortunately nothing is particularly complicated.

How familiar are you with LSL; do you know how the events work? Are you familiar with other languages or are you just starting to get into programming?

Knowing these things helps us give better examples/explanations!

  • Like 2
Link to comment
Share on other sites

The LSL wiki will be where you want to go to read up on functions' documentation. If you are brand new to LSL coding (or programming in general), there are numerous tutorials there that can help you get acclimated (And we can provide additional answers).

Generally speaking, a generic script can be written that would go into the food item. Basically, when the item is clicked, it does several things:

  • Send a message to the avatar that clicked it which has information that would tell the HUD what meter to fill. llRegionSayTo on a private channel won't be seen by the target avatar, but all attachments (like the HUD) can potentially hear it if they are listening on the same channel and have an appropriate filter.
  • Change it's alpha values to go invisible
  • Set a global variable that the food item can check to see if it's been clicked - so it can reject future clicks until the timeout elapses and it is made clickable again.
  • Start a timer which once it expires, resets the item: making it visible again and priming it to be clickable once more.

And of course the HUD itself will need to have an active listen running to hear messages from the food items.

This is just one of many possible approaches. Like Wulfie says, providing us with more info helps us give better explanations and examples.

Edited by Fenix Eldritch
  • Like 1
Link to comment
Share on other sites

I appreciate the responses. My coding is in Python and SQL. I don't know LSL coding, but I'm eager to learn. When writing Python, you need A, B, C to work for D to work But, for LSL, does it have to be written in order to proceed? Or can I write A, C, and then B, and these sections will still work?

I'm currently looking over the links Fenix provided.

  • Like 1
Link to comment
Share on other sites

1 hour ago, MarkBWalker said:

does it have to be written in order to proceed?

Yes, but also no. a very generic LSL program looks something like this:

integer gVariable1 = 0;
// <variable type> <variable name> = value;
// ...
integer my_awesome_function(integer argument/*,<arg type>,<arg value>*/)
{   // commands;
    return 7;
}
my_awesome_function_with_no_return_value_or_arguments()
{   my_awesome_function(7);
    // commands;
}
// <return type or empty> <function name> (<var type>, <var name>, <var type>, <var name>...){ <command list>}

default
{   state_entry()
    {   // commands
    }
    touch_start(integer n)
    {   // more commands
    }
    //event_name(<event arguments>)
    //{ // commands }
    // ...
}
state second_state
{   //event_name(event arguments){<event commands>}
}
state third_state
{   // event_name(event arguments){<event commands>}
}

(I'm going to name a lot of things because it makes discussion easier, I don't know if these names are 'standard')

The script has a few different sections:

  • The preamble: before the 'default' keyword, global variables and functions are declared, and variables may be assigned default values. These declarations can happen in any order.
    • a special restriction of the preamble is that 'calculation' is not allowed in variable definitions,
    • integer three = 1+1+1; // not allowed! (addiiton)
      key owner = llGetOwner(); // not allowed! (calling a function)
      integer four = 4; // valid.

      would not compile in the preamble, but ~would be allowed in a function or event command list,

  • The event list: inside the {}'s after the default keyword, event handlers for the default state are defined. These handlers may be defined in any order (swapping state_entry() and all of the contents of its {} with touch_start won't change the script)
  • Extra state sections: states can be used to define different event handlers for separate situations. statea other than default can be defined in any order (second state along with everything in its {}'s can be swapped with third_state and its {} and it will remain the same.
  • Command lists: within the {}'s of a function definition or event handler, you have lists of commands separated by ';'s. when the handler or function is executed, each command will be run in order. This means that swapping 2 lines will probably change the program, but sometimes if two lines don't affect each other, then swapping them won't change the perceived effect, because lines are executed so fast they seem simultaneous.
  • Argument lists: within the ()'s of an event handler, the order and types of the arguments are fixed, but you can change their names:
    • touch_start(integer this_is_a_very_silly_name)
      {   llOwnerSay((string)this_is_a_very_silly_name);
      }

--

Another thing to note, is that unlike Python, LSL uses curly braces and other symbols to denote logical sections rather than indentation and spacing.

integer three = 1 +
   1+
   1;

is perfectly valid (if a bit silly).

--

1 hour ago, MarkBWalker said:

display meters

Interestingly, LSL doesn't have any direct mechanism for making visuals. Everything has to be done by changing the parameters of "prims". The two most obvious ways of making a meter are by changing the length (or "slice") of a long cube, or by changing the offset of a texture, although there are other methods. (you could instead make a HUD using media functions, but that requires a lot of html+css understanding in addition to knowing lsl fluently)

Edited by Quistess Alpha
Link to comment
Share on other sites

1 hour ago, Quistess Alpha said:

(you could instead make a HUD using media functions, but that requires a lot of html+css understanding in addition to knowing lsl fluently)

I was happy to learn that I could use an in-viewer webpage just like a Media-On-A-Prim HUD (the only drawback being, the user has to click on a URL as it won't open automatically).

@MarkBWalker, I don't see where anyone mentioned it above, but the basic syntax of LSL is a lot like "C".  Events, "Scoping" (as in the "State" sections), and basic identifier types (string, integer, float, list, key, vector, rotation) are unique to LSL, but the general syntax and layout are very similar. You also get a built-in JSON library which can be extremely handy.

  • Like 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 338 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...