Login / Registrieren
DE EN FR ES IT CZ
Zurück Nach oben

Check object action exists (Lua Script)

  • #1, by darren-beckett 11 years ago Zitieren
    Can somebody please fix my script?

    if game.CurrentObject.ObjectActions[DoubleClick]:isEmpty() then
    print("No DoubleClick Action")
    end

    Error: attempt to index a nil value
  • #2, by afrlme 11 years ago Zitieren
    hmm... you forgot to wrap the name of the object action in "these", like so... "Double click".
  • #3, by darren-beckett 11 years ago Zitieren
    No, it says
    Error: DoubleClick could not be found in linklist
  • #4, by sebastian 11 years ago Zitieren
    erm yeah... what do you want to check? If there is a Double Click Action, but empty or If there is a Double Click Action at all?
  • #5, by afrlme 11 years ago Zitieren
    I'm guessing they want to check if the action exists or not so they can call another action maybe?

    It's not DoubleClick, it's Double click. Table & field names are case sensitive. They have to be written exactly as they are inside of the editor.

    Example: I have a command called left_click, now to access the action for that inside of the current object below the cursor I could do something like...
    if game.CurrentObject.ObjectActions["'left_click' executed"] ~= nil then
     print("exists")
    else
     print("does not exist")
    end
    

    ... I have no idea if what I've just written is correct though as I'm writing off the top of my head.
  • #6, by darren-beckett 11 years ago Zitieren
    Still not working.
    I have a DoubleClick action and the object below the cursor does not have a DoubleClick action assigned (It only has a LeftClick). Whichever way I write the code, it returns nil or could not be found in linklist.

  • #7, by sebastian 11 years ago Zitieren
    thats not an action you have there. these are all buttons
  • #8, by darren-beckett 11 years ago Zitieren
    These are what I select as actions for my objects.
    The objects all have actions for when the LeftClick or DoubleClick is Executeted on it.
  • #9, by afrlme 11 years ago Zitieren
    Look at my example script above.

    If you are talking about accessing an executed action inside of an object then it would be: "'DoubleClick' executed".

    * edit: I completely forgot about the command checker script I wrote ages ago. Might serve as a useful basis but not as it currently is...

    local act = game.CurrentObject.ObjectActions
    
    -- iterate through the object list with a for loop...
    for i = 1, #act do
     if i < #act then if act[i]:getName() == "'DoubleClick' executed" then
      print("DoubleClick exists"); break
     elseif i == #act and act[i]:getName() ~= "'DoubleClick' executed" then
      print("DoubleClick does not exist")
     end
    end
    
  • #10, by darren-beckett 11 years ago Zitieren
    Thanks for your help, I've now created a function i can use globally:

    function objectActionExists(obj, actionName)
    local strActionName = "'" .. actionName .. "' executed"
    local act = obj.ObjectActions
    
    	-- iterate through the object list with a for loop...
    	for i = 1, #act do
    		if act[i]:getName() == strActionName then
    			return true
    		end
    	end
    	return false
    end
    
  • #11, by Lebostein 11 years ago Zitieren