Not able to access plugin fields in element action

I have this:


It simply keeps returning -0.2 in the console. When I try changing the value in the element field in my test app, the console keeps returning -0.2.

Am I doing something wrong? I feel like I accessed fields with properties.field_name before…

Whole code bellow for context:


function(instance, properties, context) {
    const simplex = new SimplexNoise();
    
    const FIXED_COLS = 20;
    const FIXED_ROWS = 20;

    // Get noise scale properties with defaults
    const ELEVATION_SCALE_1 = properties.elevation_scale_1 || 0.05;
    const ELEVATION_SCALE_2 = properties.elevation_scale_2 || 0.1;
    const MOISTURE_SCALE_1 = properties.moisture_scale_1 || 0.03;
    const MOISTURE_SCALE_2 = properties.moisture_scale_2 || 0.08;
    
    // Log noise scales
    //console.log('Noise Scales:', {
    //    elevation: {
    //        scale1: ELEVATION_SCALE_1,
    //        scale2: ELEVATION_SCALE_2
    //    },
    //   moisture: {
    //        scale1: MOISTURE_SCALE_1,
    //        scale2: MOISTURE_SCALE_2
    //    }
    //});
    
    // Water thresholds (keeping from original)
    const WATER_THRESHOLD = properties.water_treshold || -0.2;
    console.log(WATER_THRESHOLD);
    
    // Moisture zones (1-6, where 6 is wettest)
    const MOISTURE_LEVELS = {
        VERY_DRY: { threshold: -0.6, zone: 1 },
        DRY: { threshold: -0.2, zone: 2 },
        MODERATE: { threshold: 0.0, zone: 3 },
        WET: { threshold: 0.2, zone: 4 },
        VERY_WET: { threshold: 0.4, zone: 5 },
        SATURATED: { threshold: 1.0, zone: 6 }
    };

    // Biome mapping based on elevation (longitude) and moisture
    function getBiome(elevation, moistureZone) {
        if (elevation <= WATER_THRESHOLD) {
            return 'water';
        }
        
        // Normalize elevation to 1-4 zones (low to high)
        const elevZone = Math.floor((elevation + 1) * 2) + 1;
        
        // Biome matrix based on Whittaker diagram
        const BIOME_MATRIX = {
            4: {
                1: 'scorched',
                2: 'bare',
                3: 'tundra',
                4: 'snow',
                5: 'snow',
                6: 'snow'
            },
            3: {
                1: 'temperate_desert',
                2: 'temperate_desert',
                3: 'shrubland',
                4: 'taiga',
                5: 'taiga',
                6: 'taiga'
            },
            2: {
                1: 'temperate_desert',
                2: 'grassland',
                3: 'grassland',
                4: 'temperate_deciduous_forest',
                5: 'temperate_deciduous_forest',
                6: 'temperate_rain_forest'
            },
            1: {
                1: 'subtropical_desert',
                2: 'grassland',
                3: 'tropical_seasonal_forest',
                4: 'tropical_seasonal_forest',
                5: 'tropical_rain_forest',
                6: 'tropical_rain_forest'
            }
        };

        return BIOME_MATRIX[elevZone][moistureZone] || 'unknown';
    }

    let terrainData = [];
    for (let row = 0; row < FIXED_ROWS; row++) {
        for (let col = 0; col < FIXED_COLS; col++) {
            // Calculate elevation using two noise scales
            const elevNoise1 = simplex.noise2D(col * ELEVATION_SCALE_1, row * ELEVATION_SCALE_1);
            const elevNoise2 = simplex.noise2D(col * ELEVATION_SCALE_2, row * ELEVATION_SCALE_2);
            const elevation = (elevNoise1 + elevNoise2) / 2;
            
            // Calculate moisture using two different noise scales
            const moistNoise1 = simplex.noise2D(col * MOISTURE_SCALE_1 + 1000, row * MOISTURE_SCALE_1 + 1000);
            const moistNoise2 = simplex.noise2D(col * MOISTURE_SCALE_2 + 1000, row * MOISTURE_SCALE_2 + 1000);
            const moisture = (moistNoise1 + moistNoise2 ) / 2;
            
            // Determine moisture zone
            let moistureZone = 1;
            for (const [_, data] of Object.entries(MOISTURE_LEVELS)) {
                if (moisture <= data.threshold) {
                    moistureZone = data.zone;
                    break;
                }
            }
            
            // Get biome based on elevation and moisture
            const biome = getBiome(elevation, moistureZone);
            
            terrainData.push({
                id: row * FIXED_COLS + col + 1,
                elevation: elevation,
                moisture: moisture,
                moistureZone: moistureZone,
                biome: biome
            });
        }
    }

    instance.data.terrainData = terrainData;
    const hexdataJSON = JSON.stringify(terrainData);
    instance.publishState('hexdata', hexdataJSON);
}

I think I might have an answer: fields are not accessible through actions?

Hey @contato60,

I recommend posting in Plugin builders instead

I had the same issue a few weeks back and just casted the value of properties to properties.data.newvalue and used that in the action

element properties are available in the update function.
actions have a different set of properties that you can define.
if you need a property defined for update to be available in actions you need to assign it to a property of instance.data that is also available in actions.

1 Like