Skript: General issues with some syntaxes when using entities within variables

Created on 2 Jun 2018  路  12Comments  路  Source: SkriptLang/Skript

on right click:
    if target living entity is set:
        myFunction(targeted entity)

function myFunction(e: entity):
    damage {_e} by 3 hearts

this should damage the targeted entity by 3 hearths, but it just doesn't do anything. it doesn't output any errors.

bug completed medium

All 12 comments

pretty sure this is an issue with your code

Confirmed:
image

I think function paramaters has some issues, I have heard a few times issue about using has item condition with a player parameter. I will try that.

Just tested it:

function test(p: player) :: boolean:
    if {_p} has stone:
        return true
    return false

image

Works when i use {_p}'s inventory has stone and items in {_p} returns slot list correctly.

on sneak toggle:
    player isn't sneaking
    myFunction(player)

function myFunction(p: player):
    broadcast "%{_p}%"
    damage {_p} by 3 

It also doesn't work with players, though it broadcasts their names, that seems actually logical since it neighter works with entities. I also tried using living entity in the parameter, no luck.

Another strange thing is that if you try to use play hurt on {_e} in the function it warns you that hurt can only be played on entities, this is useless in this case because variables are dynamic, the warn should only occure when using a invailid static type

Making this issue the main one for these types of bugs (the many we've referenced above in other issues). There's seemingly some general issues with how certain (or all?) expressions/effects, such as removing a potion effect or damaging an entity, work with entities stored in variables. Needs investigating.

After some debugging - functions are not the problem in any of the mentioned issues, neither are entities. Variables are the problem.


TL;DR the issue described in OP seems to affect any syntax which contains an expression that accepts multiple types, and a variable of type other-than-the-first-one is used. As an example, the syntax of EffHealth is damage %slots/livingentities/itemstack% .... When you do damage {_some.slot} ... it will work, but not damage {_some.player} ... nor damage {_some.itemstack} ...

Let's keep using EffHealth as an example - it calls damageables.getArray(e)

https://github.com/SkriptLang/Skript/blob/c3febaedb89a7ed00223bcceb44971951f06f011/src/main/java/ch/njol/skript/effects/EffHealth.java#L108

damageables is a variable, and Variable#getArray(Event) (Variables extend Expression) returns an empty array for entities. It is supposed to return:

  • if the variable is a list variable, an array converted to the required type
  • if the variable is a single variable, an array consisting only of one element, converted to the required type
  • an empty array when the conversion or something else fails (because Skript always errors silently, by an interesting design)

The thing is that the parser somewhere (I'm yet to find the exact place in code, and update this issue with the respective information, unless someone does it before me) determines that the variable should be of the first possible type, a Slot in this case

IntelliJ debugger output

Since a CraftPlayer cannot be converted to a Slot, the returned array is empty, hence nothing is looped in EffHealth, and as a result nothing happens.


  • #1313 turned out to be a very different issue
  • #1363 - I didn't manage to reproduce it
  • #1393 is an exact duplicate of the bug in OP
  • #1324 - I don't see how this could be related

Actually turns out that @bensku has discovered all of this already back in 2016

And that means that #59 is a duplicate of this issue (or, more precisely, this issue of #59, but this one has more information)

@Nicofisi Sorry for late response. Anyway... The parser bug I explained in that comment was supposedly fixed in dev30. I'm a bit puzzled now...

Hi,
CarloDrift found this bug, wich is related to this issue :

command /cmd1:
    trigger:
        while player is online:
            broadcast "&a1 ok"
            wait 2 seconds

function funcWhile(p: offline player):
    while {_p} is online:
        broadcast "&a2 ok"
        wait 2 seconds
command /cmd2:
    trigger:
        funcWhile(player)

/cmd1 works but not /cmd2 (there is not broadcast)

so sorry, but it's not completed @Nicofisi ^^

@noftaly "completed" means that this will be available in the next Skript release :)

Oh ok ty 馃槂

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DeagoTheDoggo picture DeagoTheDoggo  路  3Comments

cyanide43 picture cyanide43  路  4Comments

TheClassic36 picture TheClassic36  路  3Comments

TrademarkTM picture TrademarkTM  路  4Comments

ghost picture ghost  路  3Comments