# custom verse device is not working the way it should be

**URL:** <https://forums.unrealengine.com/t/custom-verse-device-is-not-working-the-way-it-should-be/1287309>\
**Category:** Programming & Scripting\
**Tags:** unresolved-external-, unreal-editor-for-fortnite, fortnite-creative, Scripting, question, fortnite\
**Created:** [September 7, 2023, 9:43pm UTC](https://forums.unrealengine.com/t/custom-verse-device-is-not-working-the-way-it-should-be/1287309 "2023-09-07T21:43:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheRealGwH](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@TheRealGwH](https://forums.unrealengine.com/u/TheRealGwH)\
**Post date:** [September 7, 2023, 9:43pm UTC](https://forums.unrealengine.com/t/custom-verse-device-is-not-working-the-way-it-should-be/1287309/1 "2023-09-07T21:43:03Z")

</div>

I wanted to create a device that when you press the button, takes from your 10 gold using a conditional button device and gives you a weapon using the item granted device, and every time you press the button device it gives you a better weapon for 10 gold

```auto
    var Agent : [agent]int = map{}

    @editable
    Button : button_device = button_device{}
    @editable
    ItemGranter : []item_granter_device = array{}
    @editable
    ItemSeller : []conditional_button_device = array{}
    @editable
    ItemCost: type{X: int where X >= 0} = 10

    # Runs when the device is started in a running game
    OnBegin<override>()<suspends>:void=
        Button.InteractedWithEvent.Subscribe(AssultRifle)

    AssultRifle(Player:agent):void=
        GranterNumber :int= 0
        KeyItemIndex :int= 0
        if (ItemCost > 0, ItemSell := ItemSeller[1]):
            PlayerGold := ItemSell.GetItemCount(Player, KeyItemIndex)
            if (PlayerGold >= ItemCost):
                ItemSell.SetItemCountRequired(KeyItemIndex, ItemCost)
                ItemSell.Activate(Player)
                WeaponGrant(Player, GranterNumber)
            else:
                Print("Player does not have enough money :(")
        else:
            WeaponGrant(Player, GranterNumber)

    WeaponGrant(Player: agent, GranterNumber : int):void=
        if:
            var CurrentItemIndex : int = Agent[Player]
            ItemGrant := ItemGranter[GranterNumber]
        then:
            set CurrentItemIndex += 1
            ItemGrant.SetNextItem(CurrentItemIndex)
            ItemGrant.GrantItem(Player)
            if (set Agent[Player] = CurrentItemIndex):
        else:
            if:
                set Agent[Player] = 0
                FirstItem := ItemGranter[GranterNumber]
            then:
                FirstItem.GrantItem(Player)

```

The code works overall fine but when you have more than 10 gold it drains all your gold with a single button click I used **SetItemCountRequired** to change the price from 0 to 10 gold. I don’t know if it’s a glitch from a device or there is something wrong with my script

Here is a video:

[https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/b/1/8b12f80b47466db127ee94fe9cc959778ea60e83.mp4](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/b/1/8b12f80b47466db127ee94fe9cc959778ea60e83.mp4)
  
As you see I gave myself 2500 gold and the price was 10 gold and still conditional button take it all. When I tried to interact with the conditional device itself it took from me 10 gold but with my device all the gold.

---

<div class="post-metadata">

**Author:** ![im\_a\_lama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/im_a_lama/32/995063_2.png) [@im\_a\_lama](https://forums.unrealengine.com/u/im_a_lama)\
**Post date:** [September 9, 2023, 2:20am UTC](https://forums.unrealengine.com/t/custom-verse-device-is-not-working-the-way-it-should-be/1287309/2 "2023-09-09T02:20:16Z")

</div>

Isn’t your item granter set to `On Grant Action: Clear Inventory` by any chance ? 🙂

---

<div class="post-metadata">

**Author:** ![TheRealGwH](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@TheRealGwH](https://forums.unrealengine.com/u/TheRealGwH)\
**Post date:** [September 9, 2023, 2:35pm UTC](https://forums.unrealengine.com/t/custom-verse-device-is-not-working-the-way-it-should-be/1287309/3 "2023-09-09T14:35:54Z")

</div>

Actually yes I was focusing on the code itself that I forgot about item granter settings  
I fixed this yesterday but I forgot to post it here, Thanks for the replay all good now.

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [October 9, 2023, 2:36pm UTC](https://forums.unrealengine.com/t/custom-verse-device-is-not-working-the-way-it-should-be/1287309/4 "2023-10-09T14:36:02Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
