Variables Cannot be used here

  • 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 comminuty!

    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!

Status
Not open for further replies.

MrGametop1

Member
Mar 10, 2017
36
0
6
24
Code:
function buyshop(p: player, i: item type, price: integer):
Code:
give a {_i} to the {_p}

When i reload it in skript it says:
Variables cannot be used here.
 
Post all function code
Code:
function buyshop(p: player, i: item type, price: integer):
    set {_i} to {_i} parsed as item type
    #{_p} = Spilleren
    #{_i} = Item der skal købes
    #{_price} = Prisen på {_i}
    if {@debug} is true:
        message "debug" to {_p}
    if {_p}'s balance is more or equal to {_price}:
        if {@debug} is true:
            message "Sucess du har nok penge" to {_p}
        if {_p} doesn't have enough space for 1 of {_i}:
            message "&4FEJL: &cDin inventory har ikke plads til 1 %{_i}%" to {_p}
        else:
            if {@debug} is true:
                message "Sucess din inventory er ikke fuld" to {_p}
            remove {_price} from {_p}'s balance
            message "&aDer er blevet trukket &2%{_price}%&a fra din konto" to {_p}
            message "&aDer er blevet tilføjet 1 &2%{_i}%&a til din inventory" to {_p}
            #set {_i} to {_i} parsed as object #Virker ikke
            #give 1 {_i} to the {_p} #Virker ikke
            #give a {_i} to the {_p}
            give a {_i} to the {_p} #Denne giver fejl skal rettes
            
    else:
        message "&4FEJL: &cDu har ikke nok penge på din konto" to {_p}
 
Code:
function buyshop(p: player, i: item type, price: integer):
    set {_i} to {_i} parsed as item type
    #{_p} = Spilleren
    #{_i} = Item der skal købes
    #{_price} = Prisen på {_i}
    if {@debug} is true:
        message "debug" to {_p}
    if {_p}'s balance is more or equal to {_price}:
        if {@debug} is true:
            message "Sucess du har nok penge" to {_p}
        if {_p} doesn't have enough space for 1 of {_i}:
            message "&4FEJL: &cDin inventory har ikke plads til 1 %{_i}%" to {_p}
        else:
            if {@debug} is true:
                message "Sucess din inventory er ikke fuld" to {_p}
            remove {_price} from {_p}'s balance
            message "&aDer er blevet trukket &2%{_price}%&a fra din konto" to {_p}
            message "&aDer er blevet tilføjet 1 &2%{_i}%&a til din inventory" to {_p}
            #set {_i} to {_i} parsed as object #Virker ikke
            #give 1 {_i} to the {_p} #Virker ikke
            #give a {_i} to the {_p}
            give a {_i} to the {_p} #Denne giver fejl skal rettes
          
    else:
        message "&4FEJL: &cDu har ikke nok penge på din konto" to {_p}
A have found a way to fix it, but you need to change some parts of your code.
You'll need loop splayer's inventory slots first. If slot is air, then set slot to {_i} then stop loop, because if not, will fill all inventory spaces with the item.
If my code doesn't work, the solution is near.
I get no errors.

Code:
function buyshop(p: player, i: item type, price: integer):
    #{_p} = Spilleren
    #{_i} = Item der skal købes
    #{_price} = Prisen på {_i}
    if {@debug} is true:
        message "debug" to {_p}
    if {_p}'s money is {_price}:
        if {@debug} is true:
            message "Sucess du har nok penge" to {_p}
        if {_p} doesn't have enough space for 1 of {_i}:
            message "&4FEJL: &cDin inventory har ikke plads til 1 %{_i}%" to {_p}
        else:
            if {@debug} is true:
                message "Sucess din inventory er ikke fuld" to {_p}
            remove {_price} from balance of {_p}
            message "&aDer er blevet trukket &2%{_price}%&a fra din konto" to {_p}
            message "&aDer er blevet tilføjet 1 &2%{_i}%&a til din inventory" to {_p}
            #set {_i} to {_i} parsed as object #Virker ikke
            #give 1 {_i} to the {_p} #Virker ikke
            #give a {_i} to the {_p}
            set {_num} to 0
            loop 36 times:
                if slot {_num} of {_p} is air:
                    set slot {_num} of {_p} to {_i}
                    stop loop
                add 1 to {_num}
         
    else:
        message "&4FEJL: &cDu har ikke nok penge på din konto" to {_p}
 
  • Like
Reactions: jonawoning
Status
Not open for further replies.