Skip to main content

On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

It seems like adding code to map.gd anywhere lead to freeze of the map. Here is my code to the end of _ready()


extends Control

#warning-ignore:unused_class_variable
var mouse_in = false
#warning-

ignore:unused_class_variable
var dragging = false
onready var size = $TextureRect.get_size()
var
offset = Vector2()
var status = 'none'
var timer = 0

var currentloc = null

var newNode = find_node("sea").duplicate()
newNode.rect_position = Vector2(100,100)
newNode.name = "newZone"
find_node("roads").add_child(newNode)

func _ready():
    for i in get_node("TextureRect/roads").get_children() +
get_node("TextureRect/towns").get_children():
        i.connect

("mouse_entered",self,'showtooltip',[i])
        i.connect

("mouse_exited",self,'hidetooltip')

func _input(event):
    if self.is_visible_in_tree() == false:
    

    return
    if event.is_action_pressed("LMB"):
        var eventpos =
event.global_position
        var barpos = $TextureRect.get_global_position()
        size =
$TextureRect.get_size()
        var target_rect = Rect2(barpos.x, barpos.y, size.x, size.y)
    

    if target_rect.has_point(eventpos):
            status = 'clicked'
        

    offset = barpos - eventpos
    if event.is_action_released("LMB"):
        status
= 'none'
    if status == 'clicked' and event.is_class("InputEventMouseMotion"):
        

status = 'dragging'
    #centermap('frostford')
    if status == 'dragging':
        

$TextureRect.set_global_position(event.global_position+offset)

So I said "The following can be added to the beginning of _ready() in map.gd."

You have: "The following code added before the beginning of _ready() in map.gd."

Spot the difference? It freezes cause you put local-scope code in the file-scoped portion of the code, which is completely undefined behavior.  I tried to be quite precise with my description, because there are very few locations you can put this code in the file to get the expected behavior. Perhaps I was too concise, but I am going to sleep now. The code I gave you only works inside a function and not inside a for loop.