Solved Editing local variables edits global ones?

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

xUndefined

Active Member
Jan 29, 2017
156
12
18
27
Sorry for the title, i dont really know what to put there but that.

So, I have been making a skript to create, open and see item crates.

Everything working fine, but the function that shows the items a crate holds made me realise something nasty.

Skript: Bensku fork dev26f
Minecraft: 1.11
Addons: ExtrasSK 1.1, RandomSK 2.7.1, SharpSK 1.6.1.3, Skellett 1.8.8a, SkMorkaz 0.21, SkQuery 3.5.5-Lime, SkRayFall 1.9.7, SkStuff 1.6.4.1, SkUtilities 0.8.8, Umbaska 3-dev34
Searched the docs.
Searched the forum, or at least I tried.
No other methods tried, its probably the only way i can make it work.

Code:
code_language.skript:
set {_counter} to 0
loop {suministros.objetos.%{_chest}%::*}:
        add 1 to {_loop}
        {_loop} is higher or equal to ({_point} + 1)
        {_counter} is higher than 44:
            stop loop
        set {_item} to {suministros.objetos.%{_chest}%::%loop-index%}
        set {_percent} to {suministros.weight.%{_chest}%::%loop-index%}/{_w}*100
        set {_percent} to "%{_percent}%"
        replace all "." with "," in {_percent}
        if lore of {_item} is not "":
            set lore of {_item} to "%lore of {_item}%||&8------------------------------||&dProb: &7%{_percent}%%%"
        else:
            set lore of {_item} to "||&dProb: &7%{_percent}%%%"
        {_j} has permission "admin":
            set lore of {_item} to "%lore of {_item}%||&5Id: &9%loop-index%||&fProb: &8%{suministros.weight.%{_chest}%::%loop-index%}%/%{_w}%"
        set slot {_counter} of current inventory of {_j} to {_item}
        add 1 to {_counter}


What I'm trying: I stored an item in the list variable beforehand, I want to show that item on a chest, with its lore and everything the item has when you receive it, and also i want it to show, on another line of lore, the probability when it's being shown this way. Hence why i tried modifying the lore of the item this way.

What happens: I have been using Skript for a year and a half now, and I think this shouldn't be happening at all.
code_language.skript:
set {_item} to {suministros.objetos.%{_chest}%::%loop-index%}
The global variable contains an item. I just want to copy the item to the local variable so i can edit it (to show the probability) without editing the stored item.

However, when I edit the local variable {_item}, the global variable {suministros.objetos.%{_chest}%::%loop-index%} gets edited too.

I have no clue at all why is this happening. The code works wonders, but each time i execute it, the probability gets added again to the item, showing things like this...

4gcSKDp.png

(The code is the same, just in spanish, my native language. The code I posted above just got translated so you can understand it a little better, Probabilidad=prob, Identificador=Id, Probabilidad exacta=Prob)

For what i can only assume not only {_item} is being edited, {suministros.objetos...} is edited too.


So, what I want to know: it is intended and I need to find a workaround, or is it not? If it's not, does it happens with other versions? Should i report it directly to Bensku?

Additional variable info: {suministros.weight.%{_chest}%::%loop-index%} contains a number, that's the weight of the item as im using a weight system.
 
Sorry for the title, i dont really know what to put there but that.

So, I have been making a skript to create, open and see item crates.

Everything working fine, but the function that shows the items a crate holds made me realise something nasty.

Skript: Bensku fork dev26f
Minecraft: 1.11
Addons: ExtrasSK 1.1, RandomSK 2.7.1, SharpSK 1.6.1.3, Skellett 1.8.8a, SkMorkaz 0.21, SkQuery 3.5.5-Lime, SkRayFall 1.9.7, SkStuff 1.6.4.1, SkUtilities 0.8.8, Umbaska 3-dev34
Searched the docs.
Searched the forum, or at least I tried.
No other methods tried, its probably the only way i can make it work.

Code:
code_language.skript:
set {_counter} to 0
loop {suministros.objetos.%{_chest}%::*}:
        add 1 to {_loop}
        {_loop} is higher or equal to ({_point} + 1)
        {_counter} is higher than 44:
            stop loop
        set {_item} to {suministros.objetos.%{_chest}%::%loop-index%}
        set {_percent} to {suministros.weight.%{_chest}%::%loop-index%}/{_w}*100
        set {_percent} to "%{_percent}%"
        replace all "." with "," in {_percent}
        if lore of {_item} is not "":
            set lore of {_item} to "%lore of {_item}%||&8------------------------------||&dProb: &7%{_percent}%%%"
        else:
            set lore of {_item} to "||&dProb: &7%{_percent}%%%"
        {_j} has permission "admin":
            set lore of {_item} to "%lore of {_item}%||&5Id: &9%loop-index%||&fProb: &8%{suministros.weight.%{_chest}%::%loop-index%}%/%{_w}%"
        set slot {_counter} of current inventory of {_j} to {_item}
        add 1 to {_counter}


What I'm trying: I stored an item in the list variable beforehand, I want to show that item on a chest, with its lore and everything the item has when you receive it, and also i want it to show, on another line of lore, the probability when it's being shown this way. Hence why i tried modifying the lore of the item this way.

What happens: I have been using Skript for a year and a half now, and I think this shouldn't be happening at all.
code_language.skript:
set {_item} to {suministros.objetos.%{_chest}%::%loop-index%}
The global variable contains an item. I just want to copy the item to the local variable so i can edit it (to show the probability) without editing the stored item.

However, when I edit the local variable {_item}, the global variable {suministros.objetos.%{_chest}%::%loop-index%} gets edited too.

I have no clue at all why is this happening. The code works wonders, but each time i execute it, the probability gets added again to the item, showing things like this...

4gcSKDp.png

(The code is the same, just in spanish, my native language. The code I posted above just got translated so you can understand it a little better, Probabilidad=prob, Identificador=Id, Probabilidad exacta=Prob)

For what i can only assume not only {_item} is being edited, {suministros.objetos...} is edited too.


So, what I want to know: it is intended and I need to find a workaround, or is it not? If it's not, does it happens with other versions? Should i report it directly to Bensku?

Additional variable info: {suministros.weight.%{_chest}%::%loop-index%} contains a number, that's the weight of the item as im using a weight system.
That's the 3rd item and it got 3x lore. Yust try to
code_language.skript:
delete {_item}
at the very first line of the loop.
 
I would report this to bensku, the variable should not be edited throughout a local variable, the only way to edit variables should be setting them directly.
 
Status
Not open for further replies.