#How do I stop generating the grass 2 times

1 messages · Page 1 of 1 (latest)

torn ridge
#

I am trying to generate a world like terraria (but very simple), and I am having issues with it generating the world twice. I am trying to switch from Gamemaker to Godot, but I am having so many issues with this, lol

#
@export var timer := 500;
var grass = preload("res://grass.tscn");

var x = 1920 / 2
var y = 1080 / 2

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
    pass # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
    timer -= 1 * delta;
    
    
    if timer > 0:
        
        x += 64
        var _ran = randf_range(1,3);
        if _ran >= 2.5:
            y += 64;
        if _ran <= 1.5:
            y -= 64;
        
        _grass(0);

func _grass(of):
    var __grass = grass.instantiate()
    __grass.position = Vector2(x,y - of * 64)
    add_child(__grass);
urban crater
#

The ; everywhere aren't helping, please get rid of them.

It's a timer, time is measured in seconds so make it a float

@export var timer := 500 # int ❌ 
@export var timer := 0.5 # ✔️ 
@export var timer: float = 0.5 # ✔️

timer -= delta
if timer > 0.0:

As for the double terrain, check the scene and the globals in project properties, there is more than one node with this script I think.

dim snow
torn ridge
torn ridge
dim snow
#

Any game which handles large amount of data (e.g. Terraria, Minecraft, Factorio, Noita, etc) is going to require a smart implementation and lots of optimizations. Godot scenes are not particularly light weight. I think a TileMapLayer could get you further, though you'll probably need a custom solution to make something really large

torn ridge