Skip to content

Commit 8d26887

Browse files
committed
added debug parameter and server config for deployment
1 parent 715e4a8 commit 8d26887

File tree

1 file changed

+27
-19
lines changed

1 file changed

+27
-19
lines changed

Defold/scripts/game_controller.script

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ local id
33
-- SERVER VARS
44
local server_adress = "localhost"
55
local server_port = "2567"
6+
local debug = true
67

78
--VARS
89
local client
@@ -12,25 +13,27 @@ local scaling = 100;
1213
local other_players = {}
1314

1415
function onStateChange(change)
15-
newx = room.state.players[id].x*scaling;
16-
newy = room.state.players[id].y*scaling;
17-
msg.post("default:/player#player", "Game State", {x = newx, y = newy});
16+
if room.state.players and room.state.players[id] then
17+
newx = room.state.players[id].x*scaling;
18+
newy = room.state.players[id].y*scaling;
19+
msg.post("default:/player#player", "Game State", {x = newx, y = newy});
1820

19-
for other_id,value in pairs(room.state.players) do
20-
if other_id ~= id and room.state.players[other_id].x and not other_players[other_id] then
21-
print(other_id, room.state.players[other_id])
22-
newx = room.state.players[other_id].x*scaling;
23-
newy = room.state.players[other_id].y*scaling;
24-
25-
created_id = factory.create("default:/other_player_factory#factory", vmath.vector3(newx, newy, 1),vmath.quat(),{},1)
26-
other_players[other_id] = created_id
27-
28-
elseif other_players[other_id] and other_id ~= id then
29-
newx = room.state.players[other_id].x*scaling;
30-
newy = room.state.players[other_id].y*scaling;
31-
-- go.set_position(vmath.vector3(newx, newy, 1), other_players[other_id])
32-
msg.post(other_players[other_id], "Game State", {x = newx, y = newy});
33-
21+
for other_id,value in pairs(room.state.players) do
22+
if other_id ~= id and room.state.players[other_id].x and not other_players[other_id] then
23+
print(other_id, room.state.players[other_id])
24+
newx = room.state.players[other_id].x*scaling;
25+
newy = room.state.players[other_id].y*scaling;
26+
27+
created_id = factory.create("default:/other_player_factory#factory", vmath.vector3(newx, newy, 1),vmath.quat(),{},1)
28+
other_players[other_id] = created_id
29+
30+
elseif other_players[other_id] and other_id ~= id then
31+
newx = room.state.players[other_id].x*scaling;
32+
newy = room.state.players[other_id].y*scaling;
33+
-- go.set_position(vmath.vector3(newx, newy, 1), other_players[other_id])
34+
msg.post(other_players[other_id], "Game State", {x = newx, y = newy});
35+
36+
end
3437
end
3538
end
3639

@@ -40,7 +43,12 @@ end
4043

4144
function init(self)
4245
msg.post(".", "acquire_input_focus");
43-
client = ColyseusClient.new("ws://" .. server_adress .. ":" .. server_port,false)
46+
if debug then
47+
client = ColyseusClient.new("ws://" .. server_adress .. ":" .. server_port,false)
48+
else
49+
server_adress = "asciigame.pvc.ifsr.de/api"
50+
client = ColyseusClient.new("wss://" .. server_adress,false)
51+
end
4452
client:join_or_create("Ascii", {}, function(err, room_instance)
4553
if err then
4654
print("ERROR JOINING ROOM")

0 commit comments

Comments
 (0)