2DWorlds Forums
Can someone tell me what is wrong with this script? - Printable Version

+- 2DWorlds Forums (http://2dworlds.buildism.net/forum)
+-- Forum: 2DWorlds (http://2dworlds.buildism.net/forum/forumdisplay.php?fid=4)
+--- Forum: Scripting (http://2dworlds.buildism.net/forum/forumdisplay.php?fid=13)
+--- Thread: Can someone tell me what is wrong with this script? (/showthread.php?tid=7936)



Can someone tell me what is wrong with this script? - Frostglacier - 08-11-2011

I'm trying to make a player that touches this script's parent teleport to a new world, but all it does for me is teleport the player to a certain position. Here's the script:

enabled = true
function OnCollided(hit)
if hit.Parent.Type == "Character" and enabled then
enabled = false
hit.Parent = game:getWorld("outside").World
hit.Position = Vec2D(77.69,63.88)
hit.Parent:remove()
enabled = true
end
end

link(script.Parent.Collided, OnCollided)

[/lua]


RE: Can someone tell me what is wrong with this script? - Chaos - 08-11-2011

I think this is what you need to do:

[lua]
function goTo(id)
local placeId = id + 0
game:load(placeId)
end

link(game.Players.ChildAdded, function(player)
link(player.Chatted, function(chat)
if string.sub(chat, 1, 5) == "goto/" then
goTo(string.sub(chat, 6))
end end) end)
[/lua]


RE: Can someone tell me what is wrong with this script? - Qwertygiy - 08-11-2011

No, that's my game teleport script, not a World teleport script...

Hang on a moment and I'll post a world-changing script.
[lua]
enabled = true
function OnCollided(hit)
if hit.Parent.Type == "Character" and enabled then
enabled = false
hit.Parent = game:getWorld("outside").World
local player = game.Players:getChild(hit.Parent.Name)
player.Parent = game:getWorld("outside").Players
hit.Position = Vec2D(77.69,63.88)
hit.Parent.Health = 0
enabled = true
end
end

link(script.Parent.Collided, OnCollided)
[/lua]

Now, assuming your new world is named "outside", that should work. If it looks like it just changed position, are your two worlds nearly identical? If so, it probably worked -- you just can't distinguish between the new World and the old one.


RE: Can someone tell me what is wrong with this script? - Frostglacier - 08-11-2011

(08-11-2011, 12:21 AM)Qwertygiy Wrote: No, that's my game teleport script, not a World teleport script...

Hang on a moment and I'll post a world-changing script.
[lua]
enabled = true
function OnCollided(hit)
if hit.Parent.Type == "Character" and enabled then
enabled = false
hit.Parent = game:getWorld("outside").World
local player = game.Players:getChild(hit.Parent.Name)
player.Parent = game:getWorld("outside").Players
hit.Position = Vec2D(77.69,63.88)
hit.Parent.Health = 0
enabled = true
end
end

link(script.Parent.Collided, OnCollided)
[/lua]

Now, assuming your new world is named "outside", that should work. If it looks like it just changed position, are your two worlds nearly identical? If so, it probably worked -- you just can't distinguish between the new World and the old one.

Okay, here's the working version:
[lua]enabled = true
function OnCollided(hit)
if hit.Parent.Type == "Character" and enabled then
enabled = false
hit.Parent = game:getWorld("outside").World
local player = game.Players:getChild(hit.Parent.Name)
player.Parent = game:getWorld("outside").Players
hit.Position = Vec2D(77.69,63.88)
enabled = true
end
end

link(script.Parent.Collided, OnCollided)
[/lua]

I think you forgot to add a parent Tongue