1. #1
    celestian's Avatar
    Join Date
    Jan 2017
    Location
    DFW, Texas
    Posts
    2,163

    dragData in onDragStart() returning true/false/nil

    Discussion came up on the discord channel and it was mentioned that one could "edit" the drag data instead of having to fill in the rest (and keep what would normally be there). I tested myself and was unable to get this to work and Moon requested I post it here for later discussions.


    Code:
        <template name="link_audiostop">
        <linkcontrol name="audioshortcut">
          <script>
            function onDragStart(button, x, y, draginfo)
              local node = window.getDatabaseNode();
              draginfo.setDescription(DB.getValue(node,"name","") .. " [stop]");
              return nil;
            end
          </script>
          <class>urlaudiostop</class>
          <icon normal="link_audio" pressed="link_audio_down" empty="button_link_empty" />
        </linkcontrol>
      </template>
    I couldn't get the "nil" return value to change the description using the above method. This is what I have that is working for now. This fills in ALL the data since the datainfo value is empty on start.


    Code:
    	<template name="link_audiostop">
        <linkcontrol name="audioshortcut">
          <script>
            function onDragStart(button, x, y, draginfo)
              local node = window.getDatabaseNode();
              draginfo.setDescription(DB.getValue(node,"name","") .. " [stop]");
              draginfo.setShortcutData("urlaudiostop",node.getPath())
              draginfo.setIcon("link_audio");
              draginfo.setType("shortcut");
              return true;
            end
          </script>
          <class>urlaudiostop</class>
          <icon normal="link_audio" pressed="link_audio_down" empty="button_link_empty" />
        </linkcontrol>
      </template>
    ---
    Coding the Official AD&D Ruleset
    My Twitch Channel for AD&D and FG related streams (See schedule for live days)
    My YouTube for FG related Tutorials and AD&D Actual Plays
    Custom Maps (I2, S4, T1-4, Barrowmaze,Lost City of Barakus)

  2. #2
    Just looked at the code. The drag object for default behavior is not created until after scripts are completed. The one passed to onDragStart/onDrag scripts is a "temp" drag object that is only used if you return true/false. So, you'll have to use the full override.

    Regards,
    JPG

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Log in

Log in