Jump to content
You are about to reply to a thread that has been inactive for 145 days.

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

Recommended Posts

Posted

Hello all,

Imagine a menu with (visually) twelve blank buttons. When the user clicks one of those buttons i like to let my script know which button has been clicked.

The idea is that those blank buttons represent an empty entry in storing information. After storing information the button will no longer be blank but will have a label that says something about the stored information.

Anyone ever tried something like this? With special (invisible) characters perhaps?

Love to hear your thoughts about this issue.

Regards,

Trivis Trizzlings

Posted (edited)

Normal spaces are just fine, but you'll have to use a different pattern of them for each button or the responses can't be distinguished, for example:

default
{
    state_entry() {
        llListen(-1, "", llGetOwner(), "");
    }

    touch_start(integer _) {
        list buttons;
        string s;
        integer b;
        integer i;
        for(b = 1; b <= 12; ++b) { // 12 buttons, each with N spaces
            s = "";
            for(i = 0; i < b; ++i) {
                s += " ";
            }
            buttons += s;
        }
                
        llDialog(llGetOwner(), "Press one of these", buttons, -1);
    }
    
    listen(integer c, string n, key id, string m) {
        integer len = llStringLength(m);
        // compute row/column from number of spaces
        llOwnerSay("You pressed the button with " + (string)len +
            " spaces (row " + (string)(4-(len-1)/3) + " column " + (string)((len-1)%3+1) + ")");
    }
}

 

Edited by Frionil Fang
  • Like 2
Posted
13 minutes ago, Frionil Fang said:
for(b = 1; b <= 12; ++b) { // 12 buttons, each with N spaces
            s = "";
            for(i = 0; i < b; ++i) {
                s += " ";
            }
            buttons += s;
        }

A very minor nitpick, but a more common method of producing a string with several repeated characters is to just take a sub string of a global "constant":

string gSPACES = "            "; // 12 spaces
//...
string ThreeSpaces = llSubString(gSPACES,0,2);

Or for this instance, you could re-use the string for the previous entry:

for(b = 1; b <= 12; ++b) { // 12 buttons, each with N spaces
    s += " ";
    buttons += s;
}
  • Like 3
Posted

Or to over-complicate things:

string repeatString(string c,integer n)
{   integer ind = 0x100; // for sanity, only repeat up to a maximum of 512 times.
 	string s;
    do 
    {  s=s+s; 
       if(ind&n) s+=c;
    }while( ind=(ind>>1) );
} // UNTESTED.

 

  • Like 1
Posted

Thank you for the spaces ideas!!!! Thought of it earlier, but in my mind was that spaces would be trimmed. But apparently not. Great reset of my mind 🙂

very much appreciated,

Trivis Trizzlings

  • Like 1
Posted
35 minutes ago, Quistess Alpha said:

A very minor nitpick, but a more common method of producing a string with several repeated characters is to just take a sub string of a global "constant":

You're right, that was embarassingly no brain. My excuse is that I uh, have a headache?

13 minutes ago, trivis said:

Thought of it earlier, but in my mind was that spaces would be trimmed.

The spaces are visually trimmed, but the messages sent are as is: lopsided whitespaced strings on a button like "A    " and "    A" will both be shown centered without leading or trailing spaces.

  • Like 2
Posted

I used your tips and advices. You can see the result in a simple online-HUD. It is for free, just search MP for "trizzles presence". The pictures on mp are still with the old way with numbers but the hud itself has been updated already.

Thanks again, you all.

  • Like 1
You are about to reply to a thread that has been inactive for 145 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
×
×
  • Create New...