[SOLVED] Check Item-Dragging & query SceneObject/Character

  • #1, z caligarimarteTuesday, 10. May 2016, 18:57 hodinky 9 years ago
    Hi, I am new to Visionaire and one of the first Things I made for my Game is a Verb Coin, and I decided that it shall be visible only when leftclicking either a Character or a SceneObject, or else Leftclicking just means a usual GoTo-Command.
    (Please forgive the Text-Wall, I am not sure how to express this in less Words, so please have Mercy.)
    Now, I already had that Interface mostly working the Way I wanted -- mostly. I had to set up several Values/Conditions (for Example whether the Object underneath the Cursor is an Exit or not, whether the Cursor currently is a dragged Item or not, whether the Verb Coin is currently displayed or not), some of which had to be changed all the Time across several Actions on Objects in the Game's World, turning Setting-Up mundane Actions into a highly tedious and unneccessarily complicated Chore. Additionally, the mostly very useful Building Blocks from one can create Actions still had some Limitations I needed to get around. So I decided I should recreate the Action for displaying the Verb Coin or doing other Things (i.e. not showing the Verb Coin on Exits or when an Item is being dragged) with a LUA-Script, as that should offer more Possibilities -- which it does, as I can tell so far (for Example, I can simply query whether the current Object under the Cursor begins with a few particular Letters marking it as an Exit, that is much more comfortable for me). However, as a Beginner, I find Visionaire's LUA-API to be slightly confusing and almost chaotic, as certain Commands seem to change their Form depending on where and how they have to be implemented, so I am at a Loss right now and start to lose Orientation.

    Right now, there are a few Things that I need and my Script should be complete:
    1) IF Item is being dragged (i.e. Cursor is an Item, about to use an Item on so./sth.) ... ELSE (no item being dragged) ...
    2) What are the LUA-Equivalents to:
    2.1) IF Current Object is a Sene Object...
    2.2) IF Current Object is a Character...
    2.3) Save Object
    2.4) Set ActiveCommand to DefaultCommand

    Sorry if these Things seem very basic, but some of them I just could not find on the Site's LUA-Documentation or this Forum, and some Things I thought I had found but then wasn't sure about the exact Syntax for implementing them. (1) has the higher Priority right now.

    If it should be any Help, here is the Code so far:
    local verbcoin = getObject("Interfaces[Verbalmünze]")
    local Erlene = getObject("Characters[Erlene]")
    if not game.CurrentScene.SceneIsMenu then
    --if CURRENT OBJECT == SCENE OBJECT OR CHARACTER (How do I get this?)
    if string.find(getObject("Game.GameCurrentObject"):getName(), "Gen_") then
    game:clearLink(GameCurrentObject)
    game:clearLink(GameActiveCommand)
    else
    -- IF ITEM IS ~NOT~ BEING DRAGGED -- NOT SURE IT WORKS:
    if game.UsedItem:isEmpty() then
    Erlene:setValue(VCharacterState, 2)
    verbcoin:setValue(VInterfaceVisible, 1)
    verbcoin:setValue(VInterfaceTimeToDestVisibility, 100)
    verbcoin:setValue(VInterfaceDestVisibility, 100)
    else -- IF ITEM ~IS~ BEING DRAGGED -- DOESN'T WORK!
    verbcoin:setValue(VInterfaceVisible, 0)
    end
    end
    --end
    end
    

    Fanoušek fóra

    145 Posts


  • #2, z sebastianTuesday, 10. May 2016, 19:13 hodinky 9 years ago
    Yeah, should be possible with lua. I just have to get home from work and i can throw together some bits and pieces i used for my scripts. Cant remember themnout of my head

    Kapitán

    2346 Posts

  • #3, z caligarimarteTuesday, 10. May 2016, 19:15 hodinky 9 years ago
    Thanks in Advance! smile

    Fanoušek fóra

    145 Posts

  • #4, z sebastianTuesday, 10. May 2016, 20:49 hodinky 9 years ago
    here are some script snippets you could use to complete your verb coin:

    Test if the current object under cursor is object or character:
    if game.CurrentObject:getId().tableId == eObjects or game.CurrentObject:getId().tableId == eCharacters then
        ...
    end
    


    Check if you have an item which is dragged:

    local itm = nil
    function item_used()
     if not game.UsedItem:isEmpty() then
      if game.UsedItem:getName() ~= itm then
       itm = game.UsedItem:getName();
       Conditions["item_used"].ConditionValue = true --maybe setalso a condition to true. just in case you need it inside your visionaire action parts
      end
     elseif game.UsedItem:isEmpty() and itm ~= nil then
      itm = nil; 
      Conditions["item_used"].ConditionValue = false
     end
    end
    
    registerEventHandler("mainLoop", "item_used")
    


    I dont know how to save the object or setting active/standard command. But you could call an action inside lua which runs then the actionparts you want...

    Kapitán

    2346 Posts

  • #5, z caligarimarteThursday, 12. May 2016, 12:08 hodinky 9 years ago
    Albeit with a slight Delay -- sorry for that -- I want to express my Gratitude for those Snippets. Both of them work: The Item-Snippet works perfectly, and while the Object-/Character-Query basically works perfectly too, after implementing that in the Script a weird Bug started to occur, and I do not know where the Problem may be hiding. (Trying to fix it is the Cause for my delayed Thanksgiving.)

    I hope I will find a Way to fix that Bug and don't want to bother anyone with it, as I will have to dig through the Depths of my (so far gladly rather small) Project. Anyway, I will describe it here for the Sake of Completion:

    If an Object/Character is being clicked, the Verb Coin will be displayed properly, and clicking One of the Command Buttons will properly execute the Command with the Verb Coin disappearing, just like it should... but then if I click the Object/Character again, then it seems (as the Action Text implies) that the Saved Object is being cleared and the Command won't be executed... but if I use the Verb Coin on one Object/Character, then on another, then on the first one again, the Verb Coin will work perfectly every single Time.

    Fanoušek fóra

    145 Posts

  • #6, z sebastianThursday, 12. May 2016, 12:26 hodinky 9 years ago
    Hmm. Does the verb coin opens when leftclick+hold or only left click and stays there open?

    Where is your "save ovject" actionpart right now? Maybe it gets overwritten somehow because activating a button also counts as left click ?

    Ps:i recognize the character in your avatar... Dies a youtubevideo exists showing it?

    Kapitán

    2346 Posts

  • #7, z caligarimarteThursday, 12. May 2016, 13:04 hodinky 9 years ago
    The Verb Coin opens on a simple Left Click and then stays open until one of the Command Buttons is being clicked or the Cursor leaves the Interface Area, then it disappears. (It did consider MouseHolding or RightClick to avoid having to make several Dependencies, but that is some Extra-Work I have to accept because I think a simple LeftClick is the most comfortable Solution for the Player -- at Least in my Eyes.)

    I did push around the "Save Object" Actionpart to several Points within the Script, and it seemed to have the same Effect as long as it is inside the Script, as long as it occurs before or within the the Query which, if true, would open the Verb Coin. (Strangely, if I call that Action before executing the Script, then the saved Object will be cleared as soon as I click one of the Commands on the Verb Coin.) Which might be an Indicator for the Interface Buttons being the Root of the Problem, so I will have another Look at those, but I still wonder why the Buttons would work well the first Time clicking an Object/Character but not anymore when clicking the same right after that... very bizarre. But I will have a Look at the Commands and Buttons.

    And yes, I did indeed upload a little Video not long ago:
    https://youtu.be/zL-kzd-AtmQ
    And another one showing her very oldschool randomized Talk-Animation:
    https://youtu.be/wUiNVa6uHCQ

    Fanoušek fóra

    145 Posts

  • #8, z sebastianThursday, 12. May 2016, 14:25 hodinky 9 years ago
    Hmm...
    I could guess also that the saved object doesnt get cleared correcy, too.
    Can you post your recent script and also screenshots from you configured action parts?

    PS: wir können hier auch gerne in Deutsch weiterreden wink

    Kapitán

    2346 Posts

  • #9, z caligarimarteThursday, 12. May 2016, 20:47 hodinky 9 years ago
    PS: wir können hier auch gerne in Deutsch weiterreden wink


    I rather keep it English -- imagine one Day somebody has the same or a similar Problem as I do now, has a Look at this Thread and, all of a sudden, a Thread marked marked "English" suddenly isn't any longer english -- rather frustrating if would have to chase anything else through Google Translator.

    the saved object doesnt get cleared


    Well, actually there is not a single Place where I explicitly called an Action to clear the saved Object, as my Pre-LUA-Prototype of the Verb Coin did not need that. (Well, it did, but only in a little else-Query to clear the saved Object in Case the Player clicks somewhere else while the Protagonist is walking toward an interactable Object... I even re-implemented that into the Script, but it doesn't even seem to have much of an Effect. In Fact...)

    ... I start to notice that the saved Object seems to be cleared not after the first Command Execution, but already when I just click on the Character/Object, move the Cursor away so the Coin disappears, and if I click the same Object again, then already its Name will no longer be displayed in the Action Text, implying it has been cleared after opening the Verb Coin a second Time regardless of whether a Command had been set and executed before. Maybe the Problem is in the Interface Actions making the Coin disappear then? Or maybe something just went wrong with the Save Object Action in the first Place...

    Can you post your recent script and also screenshots from you configured action parts?


    Since I am still very lost, I do indeed hope this may be helpful.
    Besides, as you can see, I am a little n00b'ish and didn't manage to get Action Parts in LUA working, so I clumsily created a separate Action somewhere else including nothing but a "Save Object" Action Part, so I could call that Action via startAction() in LUA -- I do not think that this should be the Cause of the Problem, but could it be (for whatever Reason)?

    So, this Script is being called by the Game's LeftClick Action:
    local verbcoin = getObject("Interfaces[Verbalmünze]")
    local Erlene = getObject("Characters[Erlene]")
    local act_save_object = getObject("Actions[SaveObj]")
    --local act_delete_object = getObject("Actions[DeleteObj]")
    
    if not game.CurrentScene.SceneIsMenu then
    	if  game.CurrentObject:getId().tableId == eObjects
    	or game.CurrentObject:getId().tableId == eCharacters then
    		if not string.find(getObject("Game.GameCurrentObject"):getName(), "Gen_") then
    			if not getObject("Conditions[drag_item]"):getBool(VConditionValue) then
    				startAction(act_save_object);
    				Erlene:setValue(VCharacterState, 2);
    				verbcoin:setValue(VInterfaceVisible, 1);
    				verbcoin:setValue(VInterfaceTimeToDestVisibility, 100);
    				verbcoin:setValue(VInterfaceDestVisibility, 100);
    			else
    				Erlene:setValue(VCharacterState, 2);
    				game:clearLink(VGameUsedItem);
    			end
    		else
    			if getObject("Conditions[drag_item]"):getBool(VConditionValue) then
    				Erlene:setValue(VCharacterState, 2);
    				game:clearLink(VGameUsedItem);
    			end
    		end
    	end
    end
    

    Fanoušek fóra

    145 Posts

  • #10, z sebastianThursday, 12. May 2016, 21:32 hodinky 9 years ago
    Your acript as it isnlooks ok so far.
    Hmm... Im not sure what buttons are in visionaire. When they also count as an object (what i assume right now) the script will also run if the button is clicked and by that the button gets saved as the current object after clicking a button...
    Maybe this is why it only works on fresh initialized verb coins...
    Very suspicious

    What you can test out is printing the current saved object to the log and check if it is always the object you clicked on and not e.g. the button:

    print(act_save_object) ;
    directly after you used the startAction line in lua.

    Then check after left clicking ingame via TAB, print log what it says.

    Kapitán

    2346 Posts

  • #11, z caligarimarteFriday, 13. May 2016, 00:17 hodinky 9 years ago
    You were most probably right about Buttons counting as Objects, either that or for some Reason the SaveObject-Action was flawed. Anyway, I've had enough of it and decided to settle with a functional albeit unclean Workaround: The LeftClick Function now has two IF-Querys (again), one for Scene Objects (i.e. NO Buttons) and one for Characters, both including a Save Objects Actionpart, while the Script no longer has these Things. An uncleanly "doppelt gemoppelte" Tautology, but it works perfectly, and the Script still makes the other Things I needed a Script for simpler and cleaner, so while I am unhappy with having wasted Time in Vain and a Longing toward unreachable Goals, as well as -- alas -- sacrificing one Line of Code you had so helpfully given me, I still can be at Peace and work more productively on this Project again.
    Also vielen herzlichen Dank für deine Hilfe! smile

    Fanoušek fóra

    145 Posts