[SOLVED] Global Variable in skript

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the community!

    Now, what are you waiting for? Join the community now!

  • LOOKING FOR A VERSION OF SKRIPT?

    You can always check out skUnity Downloads for downloads and any other information about Skript!

ctrlcheeb

New Member
Aug 4, 2023
6
0
1
EDIT: Dumb mistake I didnt notice the _ in the variable name

Hi, I was just making a simple script for my server where people can cash in tokens earned throughout for items.
I had one gui which when interacted with would set the {_cost} variable to the price. Then if they put the correct amount of tokens equal to the {_cost} variable it should work.

However since I am setting the cost variable in a different if statement outside of the scope the code doesn't work.
Here is the code I am referring to


Code:
on inventory click:
    set {_guibuy} to a new chest inventory with 6 rows named "&8&lBuy Rewards"
    set slot 0,1,2,3,4,5,6,7,8,9,10,11,12,14,15,16,17,18,19,20,24,25,26,27,28,29,30,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,50,51,52, and 53 of {_guibuy} to grey stained glass pane named " "
    set slot 13,21,23 and 31 of {_guibuy} to red stained glass pane named " "
    set slot 49 of {_guibuy} to emerald block named "&aGive Tokens"
    if name of event-inventory is "&8&lHalloween Rewards":
        if index of event-slot = 10:
            close player's inventory
            open {_guibuy} to player
            set {_cost} to 2


    if name of event-inventory is "&8&lBuy Rewards":
        if index of event-slot = 49:
            if size of lore of slot 22 of player's current inventory is not 0:
                if slot 22 of player's current inventory is pumpkin pie:
                    if the item amount of slot 22 of player's current inventory is equal to {_cost}:
                        cancel event
                        wait 2 ticks
                        close player's inventory
                        play sound "entity.player.levelup" to the player

If there is any way to maybe make the edited value of {_cost} global or return it and access the edited value later on that would be greatly appreciated
thanks
 
Last edited: