Solved Can't change variables once created.

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

BlooRooster1

Member
Feb 28, 2017
4
0
0
Hello, brand new Skripter here. I'm making a small server shop and I've run into an issue with variables. When I set up variables like this:


code_language.skript:
variables:
    {_diamondprice} = 300
    {_ironprice} = 33
    {_goldprice} = 158
    {_excprice} = 1000

Everything works, fine....BUT if I want to change for example {_diamondprice} to 200, it will not change. I save, reupload to server and /skript reload the script, but the variable continues to read 300.

I have read up on variable usage and searched the forums, but can't seem to find any reference to this. What am I missing? Thanks!


Skript Version: Skript 2.2 (dev25)
Skript Author: Bensku
Minecraft Version: 1.11
 
Last edited:
The variable event you are using only triggers if the variables aren't defined. I recommend using the "on skript load" event instead
 
Hm... tried that to no avail. Here is my full script. This is mostly just to learn and practice skript, so any other pointers are welcome as well.

code_language.skript:
on skript start:
    {_diamondprice} = 302
    {_ironprice} = 33
    {_goldprice} = 158
    {_excprice} = 1000

on npc right click:
    if citizen is named "TestTrader":
        execute player command "/balance"
        #message "&4Trader: &F Welcome to my shop, %player%"
        show an action bar from "&6Welcome to my shop, &4 %player%" to player
        open chest with 1 row named "&aTests tore" to player
        format slot 0 of player with iron ingot with lore "%{_ironprice}%" to run [execute player command "/buyiron"]
        format slot 1 of player with gold ingot with lore "%{_goldprice}%" to run [execute player command "/buygold"]
        format slot 2 of player with diamond with lore "%{_diamondprice}%" to run [execute player command "/buydiamond"]
        format slot 3 of player with diamond sword named "Excalibur" with lore "%{_excprice}%" to run [execute player command "/buyexcalibur"]
     
command /buydiamond:
    trigger:
        if balance of player is more than {_diamondprice}:
            give a diamond to player
            remove {_diamondprice} from player's balance
            execute player command "/balance"
        else:
            message "Not enough money! This costs %{_diamondprice}%"
           
command /buyiron:
    trigger:
        if balance of player is more than {_ironprice}:
            give a iron ingot to player
            remove {_ironprice} from player's balance
            execute player command "/balance"
        else:
            message "Not enough money! This costs %{_ironprice}%"
           
command /buygold:
    trigger:
        if balance of player is more than {_goldprice}:
            give a gold ingot to player
            remove {_goldprice} from player's balance
            execute player command "/balance"
        else:
            message "Not enough money! This costs %{_goldprice}%"

command /buyexcalibur:
    trigger:
        if balance of player is more than {_excprice}:
            give a diamond sword named "Excalibur" to player
            remove {_excprice} from player's balance
            execute player command "/balance"
        else:
            message "Not enough money! This costs %{_excprice}%"

Notice that im setting {_diamondprice} to 302. It was originally set for 300 and it remains that way even with skript reloads, server restarts, etc. Thanks for your help.
 
Oh the error is simple. You can't declare local variables (starting with "_") in the variable event. You need to make them global (remove the "_"). Also, use the method I suggested. Example :
code_language.skript:
on skript load:
    set {diamondprice} to 300
    #etc
 
  • Like
Reactions: BlooRooster1
Sorry, the "on skript start" was left over from changing it after "on skript load" didnt work. I have now changed the variables section to the following:

code_language.skript:
on skript load:
    {diamondprice} = 302
    {ironprice} = 33
    {goldprice} = 158
    {excprice} = 1000

And of course changed the variables names in the rest of the script.

Unfortuntately, now the variables simply read as '<none>' instead.
The fact that no one else in the script world seems to have this issue and none of the solutions suggested are working is leading me to think I have a deeper issue.
 
Sorry, the "on skript start" was left over from changing it after "on skript load" didnt work. I have now changed the variables section to the following:

code_language.skript:
on skript load:
    {diamondprice} = 302
    {ironprice} = 33
    {goldprice} = 158
    {excprice} = 1000

And of course changed the variables names in the rest of the script.

Unfortuntately, now the variables simply read as '<none>' instead.
The fact that no one else in the script world seems to have this issue and none of the solutions suggested are working is leading me to think I have a deeper issue.
In this code, you mustn't use an "=".
Basically your code is a series of conditions.
Do this :
code_language.skript:
on skript load:
    set {variable} to 300
 
Oh wow, completely overlooked that from your previous post. Thanks, this worked :emoji_relaxed:
 
Status
Not open for further replies.