Reputation: 68
This multiplayer RPG game, which i make, have a lots of problems :). This time, the problew is that, when the host place down a item with the my grid system, in remote tab(at Editor where you can see what is going on with the nodes when you ran the program) under the PlayerBuildings node nothing appears (in game the item is visible only for host) but when the client build sth is apear in remote tab but again is visible only for client!!!. Also i get this error
get_node: Node not found:"World/PlayerBuildings/@Camp1@3/MultiplayerSynchronizer" process_simplify_path: Condition "node == nullptr" is true.
Have anyone any idea??
And here is my grid base code:
extends Node2D
@onready var camp_fire = preload("res://src/Scenes/camp.tscn")
var tile_size =16
enum {OBSTACTLE, COLLECTABLE,RESOURCE}
var grid_size = Vector2(160,160)
var grid = []
func _ready():
for x in range(grid_size.x):
grid.append([])
for y in range(grid_size.y):
grid[x].append(null)
var positions = []
for i in range (50):
var xcoor = (randi() % int(grid_size.x))
var ycoor = (randi() % int(grid_size.y))
var grid_pos = Vector2(xcoor,ycoor)
if not grid_pos in positions:
positions.append(grid_pos)
func _input(event):
if GameManager.enable:
if event.is_action_pressed("LeftClick"):
var mouse_pos = get_global_mouse_position()
var multiX = int(round(mouse_pos.x)/tile_size)
var numX = multiX*tile_size
var multiY = int(round(mouse_pos.y)/tile_size)
var numY = multiY*tile_size
var new_pos = Vector2(multiX, multiY)
var new_camp_fire = camp_fire.instantiate()
new_camp_fire.name = str(new_camp_fire.name + str(multiplayer.get_unique_id()) )
new_camp_fire.set_position(tile_size*new_pos)
grid[multiX][multiY] = OBSTACTLE
get_tree().root.get_node("World").get_node("PlayerBuildings").add_child(new_camp_fire)
Upvotes: 0
Views: 836
Reputation: 68
I found the solution. I add a rpc fuction in my script and finaly it is working. The new code is that:
extends Node2D
@onready var camp_fire = preload("res://src/Scenes/camp.tscn")
var tile_size =16
enum {OBSTACTLE, COLLECTABLE,RESOURCE}
var grid_size = Vector2(160,160)
var grid = []
func _ready():
for x in range(grid_size.x):
grid.append([])
for y in range(grid_size.y):
grid[x].append(null)
var positions = []
for i in range (50):
var xcoor = (randi() % int(grid_size.x))
var ycoor = (randi() % int(grid_size.y))
var grid_pos = Vector2(xcoor,ycoor)
if not grid_pos in positions:
positions.append(grid_pos)
func _input(event):
if GameManager.enable:
if event.is_action_pressed("LeftClick"):
var mouse_pos = get_global_mouse_position()
var multiX = int(round(mouse_pos.x)/tile_size)
var numX = multiX*tile_size
var multiY = int(round(mouse_pos.y)/tile_size)
var numY = multiY*tile_size
var new_pos = Vector2(multiX, multiY)
grid[multiX][multiY] = OBSTACTLE
rpc("_item_placement",new_pos)
@rpc("any_peer","call_local","reliable")
func _item_placement(new_pos):
var new_camp_fire = camp_fire.instantiate()
new_camp_fire.name = str(new_camp_fire.name + str(multiplayer.get_unique_id()) )
new_camp_fire.set_position(tile_size*new_pos)
get_tree().root.get_node("World").get_node("PlayerBuildings").add_child(new_camp_fire)
Upvotes: 0