Variables in Function Names

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

Status
Not open for further replies.
Apr 12, 2017
36
0
0
Hello! I am trying to make a simple skript where I can easily copy and paste files to create many easy to make shops. For my code, I need the Functions to have specific names for each skript file.

code_language.skript:
options:
    shopname: TestMerchant
    name: Dealer
    item1: leather
    name1: &eLeather
    lore1: &eTest
    cost1: &eTest

on npc right click:
    npc is named "{@name}"
    open virtual dispenser inventory with name "&6&l{@name}" to player
    format gui slot 0 of player with {@item1} named "&r{@item1}" with lore "{@lore1}||&r&l${@cost1}" to run function itemone{@shopname}(player)
   
function itemone{@shopname}(p: player):
    if {_p}'s balance is below {@cost1}:
        send "&l&7[&4!&7]&r You do not have enough money to buy this item!" to {_p}
    else:
        remove {@cost1} from {_p}'s balance
        give a {@item1} named "{@name1}" with lore "{@lore1}" to {_p}
The error I am receiving is caused by the option tag. It is saying how Function names can only be letters and underscores, meaning it isn't picking up the option tag as the option itself.

Is there a way to have options in Function names? Or is there a work around? I have the idea of using commands instead, but would like to use Functions for this project. Thanks!
 
I noticed this happened to someone else earlier
Instead of doing {_p}'s balance, try
balance of {_p}
 
Wait, actually seeing your code; you're trying to remove "&etest" from player's balance, you can't do that. Not totally sure what you're trying to achieve here so mind explaining it? We can help you further that way.
 
Wait, actually seeing your code; you're trying to remove "&etest" from player's balance, you can't do that. Not totally sure what you're trying to achieve here so mind explaining it? We can help you further that way.
Lol didn't even recognize I wrote that. It is just meant to be an example. Im planning on replacing this with a number.
[doublepost=1525318588,1525298757][/doublepost]I have found a possible work-around for those interested.
code_language.skript:
options:
    shopname: shopskript1
#Set this to name of skript file, or it wont work
    name: Dealer
    item1: leather
    name1: &eLeather
    lore1: &eTest
    cost1: 5

on npc right click:
    npc is named "{@name}"
    open virtual dispenser inventory with name "&6&l{@name}" to player
    format gui slot 0 of player with {@item1} named "&r{@item1}" with lore "{@lore1}||&r&l${@cost1}" to run function itemone(player)
    
function itemone(p: player):
    set {_function.%script%} to script
    "%{_function.%script%}%" is "{@shopname}"
    if {_p}'s balance is below {@cost1}:
        send "&l&7[&4!&7]&r You do not have enough money to buy this item!" to {_p}
    else:
        remove {@cost1} from {_p}'s balance
        give a {@item1} named "{@name1}" with lore "{@lore1}" to {_p}
Hit me up if you think of a better way. Thank you!
 
Status
Not open for further replies.