LUA-script-problem (question)

  • #1, by cpt_capslockMonday, 09. September 2013, 05:36 11 years ago
    boenas scriptas all together !

    i wanted to have my mousecursor change its state to use ..by clicking the right mousebtn. and i got that so far.
    the problem is : i wanted it to do that in a "normal" scene ..but there are others like : mini-games and so on, in witch that should NOT be possible.
    So the solution i think is to set in the game main options menu the right mouse button to call an action that checks :

    if (for example the condition wich i set in a certain scene as true) is true,
    THEN call script (a)

    and in this script (script a from above) i got :
    ##################

    if current command is "Standart-Befehl"
    set command "rightclick-use"
    set cursor "ACTION-MAUS"
    else
    set cursor "default-MAUS"
    set command "Standart-Befehl"

    end if
    #################
    but this script isn't doing anything ..it is my first attempt to write a script .
    I AM A DESIGNER FOR GOD SAKE , HAVE MERCY.
    =)
    and an answer is appreciated ...so the workflow can continue.


    KlaatuVerataa NEKTu !

    _cpt

    Newbie

    13 Posts


  • #2, by afrlmeMonday, 09. September 2013, 13:02 11 years ago
    because it's not a Lua Script, it's editor action parts wink

    via Lua, there are a lot more possibilities that you can do to query if something should happen or not because we can use the "and" and/or the "or" operators to string together multiple conditions into a single query.

    you can actually do what you are wanting via the editor alone...

    you could query if scene is x...
    or simpler solution is to use a value instead of a condition because you can use infinite numbers in a value as opposed to true/false in a condition...

    if value "value_name" is 1
     do some action
    else
     if value "value_name" is 2
     do something else
    else
     do something if none of above are correct
     endif
    endif
    


    in the editor there needs to be same amount of "end" as "if"

    hope this helps you a little bit?

    Imperator

    7278 Posts

  • #3, by cpt_capslockMonday, 09. September 2013, 13:50 11 years ago
    i am confused, because logically (syntax-wise) i understand what i have to do.
    the problem is ... i would need the exact script, because :
    setcursor doesnt seem to work and i cannot find a list of commands for the engine script


    /sigh

    i know ..its annoying .. but please ?

    _cpt

    Newbie

    13 Posts

  • #4, by afrlmeMonday, 09. September 2013, 14:14 11 years ago
    can you give me a rundown on exactly what it is you are wanting to do please?

    P.S: the Lua Script syntax can be found on the old 2d wiki or via the new one...

    http://wiki.visionaire-tracker.net
    http://wiki.visionaire-tracker.net/wiki/Scripting
    http://wiki.visionaire-tracker.net/wiki/Data_Structure
    http://wiki.visionaire-tracker.net/wiki/Player_Commands
    http://wiki.visionaire-tracker.net/wiki/Basic_lua

    the data structure page contains all the readable/writable content & the scripting page gives you a few examples & information on scripting in VS. the player commands page are exclusive Lua commands for VS & the basic Lua page is just something I'm working on to introduce general Lua script basics & beyond.

    P.S: what you did in script above was actually action parts & should have been done inside of the editor itself; see attachment below for a quick example.

    P.P.S: you don't technically have to do the set cursor command if you are using multiple command buttons as you can assign a default cursor to each command/button - which means you only need to do the set cursor action part if you are wanting to set a different cursor other than the currently assigned default cursor for x command.

    Imperator

    7278 Posts

  • #5, by vozerSunday, 22. March 2015, 23:13 9 years ago
    Hey guys. taking up this topic.

    What if i want to set my cursor with the lua script? What is the code?

    I use your global command checker and then ask if a certain condition is true. if it is true, then set cursor and set command.

    --[[
    Global Command Checker [v6] (17/03/2014)
    Written by AFRLme [Lee Clarke]
    -- + --
    alternatingfrequencies@hotmail.com | skype @ AFRLme
    -- + --
    This script is donation optional. In game credit is non-negotiable.
    You are free to: ¹ use it in your game(s). ² modify the script.
    Do not remove - or edit - this comment block.
    --]]
     
    -- * local variables * --
    local cmd -- empty variables...
     
    -- * tables * --
    local t = {"look", "use"} -- add command/condition names here (should both have same name)
     
    -- * let's create the function which will determine what type of object is currently underneath the mouse cursor * --
    function checkObjCmd()
     cmd = game:getLink(VGameCurrentObject) -- store the object underneath the cursor
     -- * --
     if not cmd:isEmpty() then
      if cmd:getId().tableId == eCharacters then cmd = cmd:getLinks(VCharacterActions) else cmd = cmd:getLinks(VObjectActions) end
      for i=1, table.maxn(cmd) do getCmdCond(i) end -- for each command listed in the table check if condition exists...
     end 
    end
     
    -- * let's create the function which determines if command equals one of the stored conditions & sets condition accordingly * --
    function getCmdCond(val)
     for i=1, table.maxn(t) do
      if cmd[val]:getName() == "'" .. t[i] .. "' executed" or cmd[val]:getName() == "'" .. t[i] .. "' executed (immediate)" then getObject("Conditions[" .. t[i] .. "_cond]"):setValue(VConditionValue, true) end
     end
     if getObject("Conditions[use_cond]") == true
      set cursor "use"
      set command "use"
     else
      set cursor "look"
      set command "look"
     end
    end
     
    -- * let's create the condition for on mouse out which checks which conditions are true & resets them back to false * --
    function resetCmdCond()
     for i=1, table.maxn(t) do
      if getObject("Conditions[" .. t[i] .."_cond]"):getBool(VConditionValue) then getObject("Conditions[" .. t[i] .. "_cond]"):setValue(VConditionValue, false) end
     end
    

    cheers

    Newbie

    35 Posts

  • #6, by afrlmeSunday, 22. March 2015, 23:19 9 years ago
    Not possible to set it with Lua script as there is currently no GameCurrentCursor data structure field. You need to create some called by other action parts which contain set cursor action parts. You can call the actions you created via Lua script by using the startAction() function.

    startAction(Actions["test"])
    


    P.S: the command checker script was not created for the purpose you are intending. It was created for a coin interface system in which it automatically determines which command buttons on the interface should be active by searching for specific actions listed in the action list of the saved / current interaction object.

    Imperator

    7278 Posts