#(shabbyrene) Variable access from other script

61 messages Β· Page 1 of 1 (latest)

cloud bridge
#

Is it possible to store a value in a variable and call this variable again in another script?
As an example, in script 1 I have the following define plantpos <context.location.format[fx, fy, fz]> further down I have a run command that starts a 2nd script. This script should be able to access the variable plantpos but I I don't know how to define that?

Here is my script for the test: https://paste.denizenscript.com/View/128117

sour latchBOT
#

(shabbyrene) Variable access from other script

sour latchBOT
#

Hi I'm AutoThreadBot! Don't mind me, I'll just be adding the helper team to this thread so they can see it. A human will get to you soon.

brave mist
#

Either pass it as a definition, or inject the script.

#

I don't know where in the guide it shows you where tasks can accept definitions but...

#

!g blurring the line

crude peakBOT
brave mist
#

Procedures in the guide has examples of using definitions.

#

This can be done for tasks too.

#

!l task script container

crude peakBOT
# brave mist !l task script container

Task script containers are generic script containers for commands that can be run at
any time by command.

Generally tasks will be ran by !command run or !command inject.

The only required key on a task script container is the 'script:' key.


Task_Script_Name:

    type: task

    # When intending to run a task script via the run command with the "def:" argument to pass data through,
    # use this "definitions" key to specify the names of the definitions (in the same order as the "def:" argument will use).
    # You can optionally document a definition with [square brackets]
    definitions: name1|name2[description here]|...

    script:

    - your commands here


Group

Script Container System

brave mist
#

Or, if you need all the previous context available period in a script you can...

#

!c inject

crude peakBOT
# brave mist !c inject
Group

queue

Syntax

inject [<script>] (path:<name>) (instantly)

Short Description

Runs a script in the current queue.

Description

Injects a script into the current queue.
This means this task will run with all of the original queue's definitions and tags.
It will also now be part of the queue, so any delays or definitions used in the injected script will be accessible in the original queue.

cloud bridge
#

Okay, the inject worked. I only get a debug error message because of the teleport, but I don't know what's wrong with it.

brave mist
#

!debug

crude peakBOT
# brave mist !debug
Info: debug

If you need help with a script issue, one of the most powerful tools Denizen has to offer is full debug output. This is displaying in your console whenever scripts are running until you turn debug off. To share a debug log quickly and easily with helpers, simply run the command /denizen debug -r in-game to begin recording, then run through the part of the script you need help with, then run the command /denizen submit. This will give you a link to a paste of the debug log, which you can then copy/paste back to us!

brave mist
#

Pasting console isn't helpful to us, a debug output through these instructions help more.

cloud bridge
#

okay wait.. πŸ™‚

brave mist
crude peakBOT
# brave mist !logcheck https://paste.denizenscript.com/View/128121
Server Version

Paper version 1.20.6-151-a4f0f5c (MC: 1.20.6)

Plugin Version(s)

Citizens: 2.0.35-SNAPSHOT (build 3583) -- (:warning:Outdated build, behind by 50)
Denizen: 1.3.1-SNAPSHOT (build 7081-DEV) -- (Outdated build, behind by 5)

Checked For

@brave mist

UUID Version

4 (:white_check_mark: Online)

Java Version

21.0.4 :white_check_mark:

brave mist
#

You're slightly out of date but that isn't the issue.

#

Also that...

#

!t locationtag.format

crude peakBOT
# brave mist !t locationtag.format

Formats a LocationTag according to a specified format input.
You can request x, y, z, yaw, or pitch as full "f", short "s", or block "b" format.
eg "fx" for "full X coordinate" (like 1.051234), "syaw" for "short yaw" (like 1.03), or "bz" for "block Z coordinate" (like 1).
"world" is also available to get the world name.
If "$" is in the format, only codes prefixed with "$" will be replaced, eg "$bx but not bx" will become "5 but not bx" (allowing the safe use of unpredictable text inside the format block).

Group

identity

Returns

ElementTag

Examples
# This example does a simple format, like "1, 2, 3".
- narrate "You are at <player.location.format[bx, by, bz]>"
# This example adds colors, uses the "$" prefix to be safe from bugs, and formats like "You are at y = 32 in Space".
- narrate "<&[base]>You are at <player.location.format[y = <&[emphasis]>$by <&[base]>in <&[emphasis]>$world]>"
brave mist
#

Why are you defining the coordinates?

#

I've never used this tag before, this is returning an elementtag from what it's saying.

#

Oh I see.

#

You're using it to narrate as a debug.

#

However, that's just it. Coordinates in text form, not an actual locationtag.

#

That isn't the issue but it will be an issue if you don't teleport to use a locationtag, which in your case since you're injecting the script would be just <context.location>.

Whats happening is you're trying to - teleport a name of a player when it's expecting an entity tag, because your definition of <[player]> is just pulling a random players name, you need to just pull a random player and define that as the player, then you can just narrate their name in your debug announcement. <[player].name>

hushed knollBOT
cloud bridge
#

When a natural tree grows, the coordinates should be stored in a variable.

This variable should then be used in the teleport command as well as a random online player that is saved in player.

brave mist
#

I've said what was needed.

- teleport is failing because you're supplying it elementtags for both the entity requirement and location requirement.

Define your player as the actual random player.
Define your position as the actual position.
Your narrates should be using the tags necessary to provide information, such as <[player].name>

#

Alternatively you can have two definitions for player and player_name, but I feel like a once usage of this isn't necessary. But it's up to you if you want to do that instead.

cloud bridge
#

After a lot of trial and error it now works. I still have to figure out how it all works. I thought that for the Teleport command I would have to convert the locations data into regular x y z data, which is why I used the format at the beginning. and for the name I THOUGHT that it needed the actual name as a teleport parameter, that's why I also used <server.online_players.random.name> I didn't know that an EntityTag consists of a UUID and not the actual name. It's just my first script and since my English isn't that good it makes things more difficult to understand. I use Google Translator to communicate. So please understand if I act stupid as a newbie πŸ™‚

brave mist
#

!c teleport

crude peakBOT
# brave mist !c teleport
Group

entity

Syntax

teleport (<entity>|...) [<location>] (cause:<cause>) (entity_options:<option>|...) (relative) (relative_axes:<axis>|...) (offthread_repeat:<#>) (offthread_yaw) (offthread_pitch)

Short Description

Teleports the entity(s) to a new location.

Description

Teleports the entity or entities to the new location.
Entities can be teleported between worlds using this command.
You may optionally specify a teleport cause for player entities, allowing proper teleport event handling. When not specified, this is "PLUGIN". See !language teleport cause for causes.

Instead of a valid entity, an unspawned NPC or an offline player may also be used.

Optionally specify "relative" to use relative teleportation (Paper only). This is primarily useful only for...

brave mist
#

Ah.

#

Google translate, yeah.

cloud bridge
#

i have found a problem with my little script but i dont know why is this soo... : I tried the following:
If I set the event to: after plant grows naturally in the first script, the narrate is not executed in the second script. But if I change the event back to after plant grows from bonemeal in the first script, then the narrate is also executed in the lower script with the given variables. - Maybe you know how it works.

brave mist
#

!e block grows

crude peakBOT
# brave mist !e block grows
Group

Block

Event Lines

<block> grows

Switches

from:<age> to only process the event if the material started at a specific age.
to:<age> to only process the event if the material ended at a specific age.

Triggers

when a block grows naturally in the world, EG, when wheat, sugar canes, cacti, watermelons or pumpkins grow.

Context

<context.location> returns the LocationTag of the block that grew (still at original material state when event fires).
<context.material> returns the MaterialTag of the block's newly grown state.

Has Known Location

True - this adds switches in:<area> + location_flagged:<flag name>.

Cancellable

True - this adds <context.cancelled> and determines cancelled + cancelled:false.

brave mist
#

plant isn't a block is it?

crude peakBOT
# brave mist !debug
Info: debug

If you need help with a script issue, one of the most powerful tools Denizen has to offer is full debug output. This is displaying in your console whenever scripts are running until you turn debug off. To share a debug log quickly and easily with helpers, simply run the command /denizen debug -r in-game to begin recording, then run through the part of the script you need help with, then run the command /denizen submit. This will give you a link to a paste of the debug log, which you can then copy/paste back to us!

cloud bridge
#

I'll post soon, just be patient πŸ™‚

#

first is when i using a bonemeal on a sapling so after few secounds the narrate of the script below was executed and i see the message ingame but if i switch to after plant grows naturally the narrate dont execute... - here is my actually snippet: https://paste.denizenscript.com/View/128129

cloud bridge
brave mist
#

Ah.

cloud bridge
#

But for today I'm going to go to bed and if anyone else has an idea why Narrate isn't running or has a solution, I'll read it later πŸ˜„ it partially works. I as a player or a random player just doesn't receive a message if a tree is natural grows. Teleportation is still carried out. πŸ™‚

upbeat wagon
#

meaning the command will narrate the message to console

#

!c narrate

crude peakBOT
# upbeat wagon !c narrate
Group

player

Syntax

narrate [<text>] (targets:<player>|...) (format:<script>) (per_player) (from:<uuid>)

Short Description

Shows some text to the player.

Description

Prints some text into the target's chat area. If no target is specified it will default to the attached player or the console.

Accepts the 'format:<script>' argument, which will reformat the text according to the specified format script. See !language Format Script Containers.

Optionally use 'per_player' with a list of player targets, to have the tags in the text input be reparsed for each and every player.
So, for example, "- narrate 'hello <player.name>' targets:<server.online_players...

upbeat wagon
#

^ there is a targets: argument you can feed the player object(s) to