#cant change positions on a global script

23 messages · Page 1 of 1 (latest)

lament nacelle
#

this object is already loaded with player but I need it to run just 1 thing of code to kick start it

frail oyster
#

send the code please

lament nacelle
#

im gonna set up a on variable and == it to true on start and then turn it off

#


@onready var catball = preload("res://All_Scenes/Weapons/CatBall/CatBallWeapon.tscn")
@onready var player = $".."

var timer := Timer.new()

var enemy_list = []

var CatBallLevel = 1
var BaseDmg = 2
var Cooldown = 1

var RealDmg:
    get():
        return BaseDmg * CatBallLevel

var speed = 50

func _ready():
    timer.wait_time = Cooldown
    timer.one_shot = false
    add_child(timer)
    timer.start(Cooldown)
    z_index += 1



func _on_detect_enemys_body_entered(body):
    if enemy_list.has(body):
        pass

        
    if body.is_in_group("enemy"):
        enemy_list.append(body)

func _init():
    spawn()

func _on_detect_enemys_body_exited(body):
    if body.is_in_group("enemy"):
        enemy_list.erase(body)


func _on_player_cat_ball_equip():
    Find_Enemy()


func Find_Enemy():
    for enemy in enemy_list:
        var enemy_direction = self.global_position.direction_to(enemy.global_position)
        var enemy_distance = $"..".global_position.distance_to(enemy.global_position)
        var angle = enemy_direction.angle()
            
        if enemy_distance > 0:
            rotation = angle
            velocity = enemy_direction * speed
            move_and_slide()
    
func spawn():
    self.global_position = $"..".global_position

func _on_area_2d_body_entered(body):
    if body.is_in_group("enemy"):
        enemy_list.erase(body)
        spawn()
        print("respawned")
        ```
frail oyster
#

what are you trying to modify on the window?

lament nacelle
#

it says window cuz it cant get players position

#

I think the script loads before the player thats why it cant get it

#

is that what globals do ?

frail oyster
#

does it happen in spawn() ?

#

the parent of an autoload will always be the window

#

I'm not sure what your script is doing

lament nacelle
#

its how it was sent here is why its like that

frail oyster
#

when you make a script an autoload it doesn't make thr script itself global but a copy of it

#

it will be placed at /root/ScriptName

#

and I doubt you want your player there

lament nacelle
#

im not really understanding this unless you know how to get scene variables from other scenes this is all I know is to make it global

frail oyster
#

make an autoload with just the variables you want globally and make your player script access these

lament nacelle
#

this object is like a projectile so im not really sure how id do that and id need the projectiles movement script in its thing

frail oyster
#

Here's an example

Globals.gd

var player_speed := 10.0

Player.gd

func _physics_process()
    move_and_slide(something * Globals.player_speed)
lament nacelle
#

so this script I make global but with only the variables ?

frail oyster
#

Yes make an autoload with just variables for now

lament nacelle
#

I think ik what to do so ill be right back

lament nacelle