trivis Posted July 21 Posted July 21 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
Quistess Alpha Posted July 21 Posted July 21 7 minutes ago, trivis said: With special (invisible) characters perhaps? I believe just ordinary spaces would work. You could also try zero-width spaces https://en.wikipedia.org/wiki/Zero-width_space 1
Frionil Fang Posted July 21 Posted July 21 (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 July 21 by Frionil Fang 2
Quistess Alpha Posted July 21 Posted July 21 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; } 3
Quistess Alpha Posted July 21 Posted July 21 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. 1
trivis Posted July 21 Author Posted July 21 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 1
Frionil Fang Posted July 21 Posted July 21 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. 2
trivis Posted July 21 Author Posted July 21 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. 1
Recommended Posts
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