I want to make a shooter with LSL, so I want to measure the time between the start and the end of a left mouse click, in order to set throw velocity.
I also want to update a gui (or at least display the text like Power: 55%
etc.) let's say at each 5% increment.
How can I do that?
I really can't show anything I have done because I don't know LSL much, so I couldn't try anything. The closest I could find is this page for llTakeControls, but I'm not sure how to use it.
Thanks in advance for any help,
Edit
Based on @BlindWanderer's answer, I tried to modify it (hoping that control()
would get repeatedly called while mouse is down) but apparently this is not the case:
default
{
state_entry()
{
llRequestPermissions(llGetOwner(), PERMISSION_TAKE_CONTROLS);
}
run_time_permissions(integer perm)
{
if(PERMISSION_TAKE_CONTROLS & perm)
{
llTakeControls(CONTROL_LBUTTON, TRUE, TRUE);
}
}
control(key id, integer level, integer edge)
{
integer start = level & edge;
integer end = ~level & edge;
integer held = level & ~edge;
integer untouched = ~(level | edge);
if(start & CONTROL_LBUTTON) {
llResetTime();
}
if(end & CONTROL_LBUTTON) {
llOwnerSay((string)llGetTime());
}
// --- My attempt to display the time peridoically
float timerval = llGetTime();
llOwnerSay((string)timerval); // this doesn t fire
if(llRound(timerval*100) % 5 == 0){
llOwnerSay((string)timerval); // this neither
}
}
}
My 2nd attempt (after realizing there is a variable called held
), but again I couldn't make it work :/
default
{
state_entry()
{
llRequestPermissions(llGetOwner(), PERMISSION_TAKE_CONTROLS);
}
run_time_permissions(integer perm)
{
if(PERMISSION_TAKE_CONTROLS & perm)
{
llTakeControls(CONTROL_LBUTTON, TRUE, TRUE);
}
}
control(key id, integer level, integer edge)
{
integer start = level & edge;
integer end = ~level & edge;
integer held = level & ~edge;
integer untouched = ~(level | edge);
if(start & CONTROL_LBUTTON) {
llResetTime();
}
if(end & CONTROL_LBUTTON) {
llOwnerSay((string)llGetTime());
}
if(held & CONTROL_LBUTTON){
llOwnerSay("check");
float timerval = llGetTime();
llOwnerSay((string)timerval); // this doesn t fire
if(llRound(timerval*100) % 5 == 0){
llOwnerSay((string)timerval); // this neither
}
}
}
}