Wurdy Posted February 8, 2019 Share Posted February 8, 2019 In general, I do not understand why the script does not work. The button (cross) has number 2. I checked it using this script: default { state_entry() { } touch_start(integer num_detected) { llOwnerSay("Link number clicked: " + (string)llDetectedLinkNumber(0) ); } } Here is the script of the button itself (cross) integer close_button = 2; default { touch_start(integer n) { if(llDetectedLinkNumber(0) == close_button) { llRequestPermissions(llGetOwner(), PERMISSION_ATTACH); } } run_time_permissions(integer permission) { if(permission) { llDetachFromAvatar(); } } changed(integer change) { if(change & CHANGED_OWNER) { llResetScript(); } } } The problem is that when I press the button, nothing happens. Link to comment Share on other sites More sharing options...
Rolig Loon Posted February 8, 2019 Share Posted February 8, 2019 Well, for one thing, your request for handling the permissions is misworded. What you need is run_time_permissions(integer permission) { if(permission & PERMISSION_ATTACH) { llDetachFromAvatar(); } } On a smaller but still significant note, you're still using the link number to identify the button. That's often potentially dangerous, since you can mess up link numbers when you do later model adjustments. As a rule, it's wiser to use link names. So, for example, name your four button links "cross", "box", "dots", and "tile" and then deal with that particular button by writing touch_start(integer n) { if(llGetLinkName(llDetectedLinkNumber(0)) == "cross") { llRequestPermissions(llGetOwner(), PERMISSION_ATTACH); } } That way, you never need to know what the link number is, and you can relink the HUD at will without messing up your script. 1 Link to comment Share on other sites More sharing options...
Wurdy Posted February 8, 2019 Author Share Posted February 8, 2019 4 minutes ago, Rolig Loon said: Ну, во-первых, ваш запрос на обработку разрешений неверен. Что вам нужно На небольшом, но значимом примечании вы все еще используете номер ссылки для идентификации кнопки. Это часто потенциально опасно, так как вы можете испортить номера ссылок при последующих настройках модели. Как правило, разумнее использовать названия ссылок. Так, например, назовите ваши четыре кнопочные ссылки "крестик", "прямоугольник", "точки" и "плитка", а затем разберитесь с этой конкретной кнопкой, написав Таким образом, вам никогда не нужно знать, что такое номер ссылки, и вы можете заново связать HUD, не испортив сценарий. Wow, thanks for the tip. I just read in the function description llDetachFromAvatar quote: "Only works in the root prim of the attachment. Сalling it from a script in a child prim will cause it to fail silently". It seems to me the whole thing in this, but I just saw how the close button is used outside the parent, how is it implemented? Link to comment Share on other sites More sharing options...
Rolig Loon Posted February 8, 2019 Share Posted February 8, 2019 That's true, but I assumed that your script was already in the root prim. There's no need for any script to be in one of the child prims, after all. Link to comment Share on other sites More sharing options...
Wulfie Reanimator Posted February 8, 2019 Share Posted February 8, 2019 (edited) 2 hours ago, Rolig Loon said: Well, for one thing, your request for handling the permissions is misworded. It's not. The parameter "permission" contains the combined value of all granted permissions, which means if it is nonzero, some permissions were granted. Since the only request in the script is PERMISSION_ATTACH, it has to be that value. You don't have to check for specific values if you're only ever requesting one of them, or only auto-granted ones (which means if you got one, you got all of them). I'm explaining this because I wrote that code in a previous thread. P.S. I will agree that that's probably not the most intuitive way to do it, since it can't be applied universally. Edited February 8, 2019 by Wulfie Reanimator Link to comment Share on other sites More sharing options...
Rolig Loon Posted February 8, 2019 Share Posted February 8, 2019 Yeah, that's true, Wulfie. Like many shortcuts, though, it's easy to forget that you did it, and then get caught later when you ask for some other permission. I've made that mistake so many times that I have learned to spell things out unless I'm really confident. I screw up a lot, so I try to avoid digging new potholes for myself if I can. 🙃 2 Link to comment Share on other sites More sharing options...
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