Scale item object

  • #1, by ke4Wednesday, 30. September 2015, 12:12 5 years ago
    Hi,

    I would like to scale an item on hover, but the game is not responding to ObjectScale.
    How does this ObjectScale works? Can't get it work even with classic objects.

    game.CurrentObject.ObjectScale = 2.0
    or
    game.GameCurrentObject:setValue(VObjectScale, 2.0)
    1
    2
    3
    4


    Also i noticed that CharacterItemsScrollPosition can't be acces it gives Unknown data-field error.
    Thanks

    Key Killer

    810 Posts


  • #2, by afrlmeWednesday, 30. September 2015, 12:25 5 years ago
    I think CharacterItemScrollPosition is an old data structure field. Some of the entries on the data structure page may no longer be in recent builds as some of them were from older versions of VS. There's so many fields / tables that it's hard to keep track (well for me anyway).

    I believe the code would be:
    game.CurrentObject.Scale = 2
    1
    2

    But you would probably be better off actually linking directly to the object itself.
    game.CurrentScene.SceneObjects["test"].Scale = 2
    1
    2


    P.S: It's not a good idea to mix shorthand with getObject (longhand) methods - if possible. You should try to stick to one or the other.

    Imperator

    6817 Posts

  • #3, by ke4Wednesday, 30. September 2015, 12:38 5 years ago
    Eh i'm trying to use only the shorthand, i need to get use to use only that.

    game.CurrentObject.Scale = 2
    1
    2


    This doesn't work either.

    game.CurrentScene.SceneObjects["test"].Scale = 2
    1
    2


    This says Error: Visobj s3hasicak could not be found in linklist
    Is it still classified as an object if it's an item?

    Guess the shortest way would be?
    Objects["test"].Scale = 2
    1
    2

    Key Killer

    810 Posts

  • #4, by SimonSWednesday, 30. September 2015, 12:57 5 years ago
    ObjectScale and all that works only for scene objects, if you want to scale cursors you need the access the animation.

    Thread Captain

    1352 Posts

  • #5, by ke4Wednesday, 30. September 2015, 13:07 5 years ago
    Thanks Simon, i tried this and it works.

    ActiveAnimations[game.CurrentObject:getName()]:to(200, { AnimationSize = 110 }, easeQuintOut)
    1
    2


    Is there a reson for that items doesn't have mouse enter and leaves action the same as objects has?

    Edit: The animation doesn't look smooth, it looks like it's vibrating.

    Key Killer

    810 Posts

  • #6, by afrlmeWednesday, 30. September 2015, 13:36 5 years ago
    Ah shit, sorry. Didn't realize you was talking about items.

    You could use a mouseEvent listener to create a more global approach to this & to listen out for when mouse hovers over an object that is an item.

    You would have to store the current / previous items inside of variables to be able to scale them back down on mouse leaves.

    Imperator

    6817 Posts

  • #7, by ke4Wednesday, 30. September 2015, 13:41 5 years ago
    Yes this is what i wrote, but the animation looks buggy :/

    local currentItemName = nil
    local status

    function zoomItem()
    if game.CurrentObject.IsItem then
    ActiveAnimations[game.CurrentObject:getName()]:to(220, { AnimationSize = 115 }, easeQuadOut)
    currentItemName = game.CurrentObject:getName()
    status = true
    else
    if status == true then
    ActiveAnimations[currentItemName]:to(220, { AnimationSize = 100 }, easeQuadOut)
    status = false
    end
    end
    end
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16

    Key Killer

    810 Posts

  • #8, by afrlmeWednesday, 30. September 2015, 13:45 5 years ago
    hmm how is this function triggered?

    Imperator

    6817 Posts

  • #9, by ke4Wednesday, 30. September 2015, 13:50 5 years ago
    By my MouseEvent

    if eventType == eEvtMouseMove then mouseStatus = 1; zoomItem() end
    1
    2


    But it seems to be issue with the resizing animation, it looks the same if i execute it manually.

    Key Killer

    810 Posts

  • #10, by afrlmeWednesday, 30. September 2015, 15:36 5 years ago
    I don't think .IsItem works correctly with shorthand script. Anyway... I've rigged up a rough script that seems to do the trick. Might even use it myself.

    1. You need to make sure you create the item images under the animation tab. They should be set to infinite loop under the properties tab & if they are only a single frame, then set a high pause amount, say: 999 or something to that effect - give the engine less work to do by having it loop the frame less often. wink

    2. you will need a mouse event listener that calls the functions used to scale the items up & reset the non-active items back to default size.
    function mouseEvt(typ, pos)
    -- + --
    if typ == eEvtMouseMove then
    if game.CurrentScene:getName() == game.CurrentCharacter.Scene:getName() then scaleItem() end
    end
    -- + --
    end

    registerEventHandler("mouseEvent", "mouseEvt")
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10

    ... if you already have a mouse event handler then just add this line inside of a if type == eEvtMouseMove query. (this is just to prevent the function from triggering if current character is not on the current scene. I suppose I could have just queried if inventory was visible, but... too late now.
    if game.CurrentScene:getName() == game.CurrentCharacter.Scene:getName() then scaleItem() end
    1
    2


    3. create a new definition script & add this to it...
    --[[
    Scale Items Up / Down (on mouse enter / leave) [V2] (30/09/2015)
    Written by AFRLme [Lee Clarke]
    -- + --
    afrlme@outlook.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 ci = nil
    local itm = nil
    local state = false

    function scaleItem()
    if game.CurrentObject:getId().tableId == eObjects then
    if game.CurrentObject:getBool(VObjectIsItem) then
    if itm ~= game.CurrentObject:getName() then state = true; itm = game.CurrentObject:getName(); ActiveAnimations[itm]:to(220, {AnimationSize = 115}, easeQuadOut); resetItemScale() end
    end
    else
    itm = nil; resetItemScale()
    end
    end

    function resetItemScale()
    if state then
    ci = game.CurrentCharacter.Items
    if itm == nil then state = false end
    for i = 1, #ci do
    if ci[i]:getName() ~= itm and ActiveAnimations[ ci[i]:getName() ].AnimationSize ~= 100 then ActiveAnimations[ ci[i]:getName() ]:to(220, {AnimationSize = 100}, easeQuadOut) end
    end
    end
    end
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35


    & voila. It should work & without any errors either.

    Imperator

    6817 Posts

  • #11, by ke4Wednesday, 30. September 2015, 16:03 5 years ago
    Nice.

    I just don't get it what's the trick? What makes it more smooth? ( But it still not perfect, don't know why )
    Mine script works as well, but just not as smooth but both use :to() function

    i would just add somewhere
    game.GameUsedItem:getName() ~= game.CurrentObject:getName()
    1
    2


    Because i'm covering the dragged item with a black tile. So i guess into the 19 line?

    Key Killer

    810 Posts

Write post