Scarpet returning a value of 0 without logging errors or having a value of 0 entered
TheGreatCatAdorer opened this issue ยท 2 comments
The below code, when run as a script with ' spawn', will spawn a player with the name of 0 and never any other name. We can tell that the variable defined at line 6 pos 29 is equal to 0 by line 6 pos 37 by replacing player_spawn() with print().
Fabric-carpet version 1.4.38.
__config() -> {'scope' -> 'global', 'command_permission' -> 'all', 'allow_command_conflicts' -> 'true', 'commands' -> { '' -> _() -> print('A slightly restricted form of the /player command, for use in survival.'), '<target> spawn' -> _(t) -> player_spawn(_t), '<target> <action>' -> _(t, a) -> string_execute([t, a]), '<target> <action> <frequency>' -> _(t, a, f) -> string_execute([t, a, f]), '<target> <action> <frequency> <quantity>' -> _(t, a, f, q) -> string_execute([t, a, f, q]), '<target> <action> <frequency> <location>' -> _(t, a, f, l) -> string_execute([t, a, f, ...l]) }, 'arguments' -> { 'target' -> {'type' -> 'term', 'suggest' -> ['Steve', 'Alex']}, 'action' -> {'type' -> 'term', 'options' -> ['attack', 'dismount', 'drop', 'dropStack', 'hotbar', 'jump', 'kill', 'look', 'mount', 'move', 'sneak', 'sprint', 'stop', 'swapHands', 'turn', 'unsneak', 'unsprint', 'use']}, 'frequency' -> {'type' -> 'term', 'suggest' -> ['all', 'continuous', 'interval <integer>', 'once', 'at']}, 'quantity' -> {'type' -> 'int', 'suggest' -> [1, 20]}, 'location' -> {'type' -> 'pos'} } }; string_execute(values) -> then(string = 'player', for(values, string = string + ' ' + _), run(string) ); player_spawn(name) -> then( print(name), fake_players = 0, for(player('all'), if(query(_, 'player_type') == 'fake', fake_players += 1)), fake_player_cap = (length(player('all'))-fake_players)*4, // The '4' in the above line is a subsitute for the number of fake players per real player. if(fake_players < fake_player_cap, run('player ' + name +' spawn')), for(player('all'), if(query(_, 'player_type') == 'fake', modify(_, 'gamemode', 0))))
The spacing didn't work out?
To be clear, the below file is a being run as a .sc file.
player_control.txt
_t
is not defined in there.
When you use the _(something...)
, you are creating an anonymous function (aka lambda, basically a function that is not "completeky defined", but that it exists in that field, and can technically be passed around).
Therefore, it's the same as if you define a regular function with some parameter. It's like
function_name(param1, param2,...) -> something
Just that function_name
is _
instead to mark it as anonymous. Therefore your parameter in the function is t
, not _t
.
PS: For code blocks use triple `.