godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.93k stars 21.15k forks source link

when click the button it seems not working #84646

Closed aliule2020 closed 12 months ago

aliule2020 commented 12 months ago

Godot version

4.2 beta

System information

windows11-godot4.2 mono

Issue description

main.cs as following:

using Godot;
using System;

public partial class main : Node2D
{
    // Called when the node enters the scene tree for the first time.
    public GraphEdit ge;
    public override void _Ready()
    {
        Button btn = this.GetNode<Button>("btn1");
        btn.Text = "add data";
        btn.Pressed += btnclc;

    }

    private void btnclc()
    {
        var cs = GD.Load<PackedScene>("res://addons/easy_charts/examples/line_chart/Control.tscn");
        var node=cs.Instantiate();
                node.SetScript((GDScript)GD.Load("res://addons/easy_charts/examples/line_chart/Control.gd"));
               GetTree().ChangeSceneToPacked(cs);
               node.GetScript().AsGodotObject().Get("f1").AsGodotObject().Call("add_point", 1, 5);
      }

    // Called every frame. 'delta' is the elapsed time since the previous frame.
    public override void _Process(double delta)
    {
    }
}

the script of scene Control is control.gd as following:

extends Control

@onready var chart: Chart = $VBoxContainer/Chart

# This Chart will plot 3 different functions
var f1: Function

func _ready():
    # Let's create our @x values
    #var x: PackedFloat32Array = ArrayOperations.multiply_float(range(-10, 11, 1), 0.5)

    # And our y values. It can be an n-size array of arrays.
    # NOTE: `x.size() == y.size()` or `x.size() == y[n].size()`
    #var y: Array = ArrayOperations.multiply_int(ArrayOperations.cos(x), 20)

    # Let's customize the chart properties, which specify how the chart
    # should look, plus some additional elements like labels, the scale, etc...
    var cp: ChartProperties = ChartProperties.new()
    cp.colors.frame = Color("#161a1d")
    cp.colors.background = Color.TRANSPARENT
    cp.colors.grid = Color("#283442")
    cp.colors.ticks = Color("#283442")
    cp.colors.text = Color.WHITE_SMOKE
    cp.draw_bounding_box = false
    cp.title = "Air Quality Monitoring"
    cp.x_label = "Time"
    cp.y_label = "Sensor values"
    cp.x_scale = 5
    cp.y_scale = 10
    cp.interactive = true # false by default, it allows the chart to create a tooltip to show point values
    # and interecept clicks on the plot

    var x:PackedFloat32Array=[0]
    var y:PackedFloat32Array=[0]
    # Let's add values to our functions
    f1 = Function.new(
        x, y, "Pressure", # This will create a function with x and y values taken by the Arrays 
                        ## we have created previously. This function will also be named "Pressure"
                        ## as it contains 'pressure' values.
                        ## If set, the name of a function will be used both in the Legend
                        ## (if enabled thourgh ChartProperties) and on the Tooltip (if enabled).
        ## Let's also provide a dictionary of configuration parameters for this specific function.
        { 
            color = Color("#36a2eb"),       # The color associated to this function
            marker = Function.Marker.CIRCLE,    # The marker that will be displayed for each drawn point (x,y)
                                            # since it is `NONE`, no marker will be shown.
            type = Function.Type.LINE,      # This defines what kind of plotting will be used, 
                                            # in this case it will be a Linear Chart.
            interpolation = Function.Interpolation.STAIR    # Interpolation mode, only used for 
                                                            ## Line Charts and Area Charts.
        }
    )

    # Now let's plot our data
    chart.plot([f1], cp)

    # Uncommenting this line will show how real time data plotting works
    set_process(false)

var new_val: float = 4.5

func _process(delta: float):
    # This function updates the values of a function and then updates the plot
    #new_val += 5

    # we can use the `Function.add_point(x, y)` method to update a function
    #f1.add_point(new_val, cos(new_val) * 20)
    #f1.remove_point(0)
    chart.queue_redraw() # This will force the Chart to be updated

func _on_CheckButton_pressed():
    set_process(not is_processing())

Steps to reproduce

  1. create a 2d node and save as main scene
  2. create a button on the node
  3. add asset of easy-chats
  4. change the script as above
  5. you will see

Minimal reproduction project

test.zip

akien-mga commented 12 months ago

Hi! You seem to be looking for help to analyze why your code doesn't work the way you want it to be.

This may be due to an engine bug, but the more likely option would be a logic bug in your code. To find out about this, you should use one of the other community platforms listed on https://godotengine.org/community/ where Godot users might be willing to help you figure this out.

The issue tracker on GitHub is only for well-defined bug reports which can be clearly seen as such. Engine contributors can't afford to spend much time debugging your code to see if there's an engine bug or not.

If/when a more minimal reproducer is made that confirms that something would be wrong with the engine, then it's definitely suitable to open as a bug report.

aliule2020 commented 12 months ago

I am Sorry,but the community web address is blocked in China, do you have another way to talk about the the issues?

At 2023-11-11 04:31:01, "Rémi Verschelde" @.***> wrote:

Hi! You seem to be looking for help to analyze why your code doesn't work the way you want it to be.

This may be due to an engine bug, but the more likely option would be a logic bug in your code. To find out about this, you should use one of the other community platforms listed on https://godotengine.org/community/ where Godot users might be willing to help you figure this out.

The issue tracker on GitHub is only for well-defined bug reports which can be clearly seen as such. Engine contributors can't afford to spend much time debugging your code to see if there's an engine bug or not.

If/when a more minimal reproducer is made that confirms that something would be wrong with the engine, then it's definitely suitable to open as a bug report.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>