"Sputnik" help  
Sputnik Help
NbtCompoundGet(<nbtCompound>, <key>)

Description

Retrieves the value associated with a specific key within an NBT compound, automatically converting it to the appropriate Sputnik variable type based on the NBT tag's type.

Parameters

<nbtCompound> The NBT compound from which to retrieve the NBT tag.
<key> The key associated with the value to retrieve.

Return Value

Success: Returns the value associated with the specified key within the NBT compound, converted to the appropriate Sputnik variable type.
Failure: Returns null if the provided nbtCompound parameter is not a valid NBT compound or if the key does not exist within the compound.

Remarks

The NbtCompoundGet function allows you to retrieve the value associated with a specific key within an NBT compound. It verifies that the nbtCompound parameter is a valid NBT compound and searches for the specified key. If the key is found, the corresponding value is automatically converted to the appropriate Sputnik variable type based on the NBT tag's type, such as converting an NBT tag of type "Int" to a Sputnik integer variable.

Related

Example

Example of usage:

my $nbt = NbtNew(@NbtCompound);
NbtCompoundSet($nbt, "Cat", "Meow");
NbtCompoundSet($nbt, "Dog", "Woof");

say NbtCompoundGet($nbt, "Cat");
say NbtCompoundGet($nbt, "Dog");

// PRINTS
// Meow
// Woof

You can also iterate through the NbtCompound like so:

my $nbt = NbtNew(@NbtCompound);
say NbtCompoundIsEmpty($nbt);
NbtCompoundSet($nbt, "Cat", "Meow");
NbtCompoundSet($nbt, "Dog", "Woof");
say NbtCompoundIsEmpty($nbt);

foreach(my $c in $nbt)
    say $c;
    
foreach(my $k => my $v in $nbt)
    say $k . " -> " . $v;

// PRINTS
// true
// false
// Cat -> Meow
// Dog -> Woof

 


Contact
Cheryl (uberfox@hotmail.com)
Homepage
http://ubersoft.org