ID:1555543
 
Keywords: startup
(See the best response by Nadrew.)
How would you log a player into a world that started via startup() procedure?


 mob
Login()
.=..()
startup('Test.dmb',0)
//Log player in hosted Test.dmb's world


You need to know the IP and port of the new world.

Then link() them to the new world's corresponding byond:// address.
You can. Embed the byond:// url in an anchor tag.

startup("herp.dmb",1225)
mob << "<a href="byond://[world.address]:1225">Click to join!</a>"
OK looking at the guide this is easy...all you need to do is use link() like was said by Ter13.

Also nobody may have seen this but startup() has a return value as shown in the guide...it says it returns the address of the new server in the form ip:port

What this means is you don't even have to setup like in Ter13's example to use a specific port...you can simply use the return value and still use the random port.
What this means is you don't even have to setup like in Ter13's example to use a specific port...you can simply use the return value and still use the random port.

Ah, well, isn't that a lovely little find. I did not, in fact, know that. Good work there, Superbike.
How would one access the return value for startup() to use as an argument with link()? I'm a little brain dragged.
...calling startup() returns the return value. You assign it to a variable, or use it as an argument, just like any other return value.
Hm, I assigned a variable to the return value of startup() and yet it ran startup twice instead of expected logging client on to a different world.

mob
verb
Go()
var/s = startup('Test.dmb',6666)
startup('Test.dmb',6666)

usr << link(s)


even with just the variable assigning it starts dream dameon and the usr doesn't connect to the said server.

Does this procedure require that the port be reachable. I'm assuming it functions differently from join world button in dream dameon and that's why I can't get it to work? Can someone who can host test this for me?

Edit: Unless my ip address is changing. No.
It runs twice because you are calling it twice. The second call is not required.
link() works with websites just fine. I must be using wrong address for games somehow. The variable assigns the return value. It's not a regular call so yeh shouldn't start dream dameon twice.

startup()

Returns:
The address of the new server in the form ip:port.
It needs to be a BYOND:// url.

var/s = startup('Test.dmb',6666)
usr << link("byond://[s]")
startup() is returning the local ip of the game, so it does not need to be reachable.

The code works just fine for me. Additionally, it works fine when startup() is invoked a second time, as the second instance fails to startup.

I would ask what is on your new instance...is it possibly failing to start the server?

Edit: Ter - I did not add that and I was able to connect to the new server.
Ok not home to test but it was address. I guess the procedure executes returns and then the variable is assigned in that order.
I guess the procedure executes returns and then the variable is assigned in that order.

That's correct.

Generally speaking, procedures cannot return until the end of an execution path is reached. When a program enters an execution path, it begins execution.

The VM receives the following pattern:

var/a = someproc()


as:

(push) call <scope> someproc
set a <local>


call is implied to push a final value into the stack when it has a left-hand value pairing. Call is an unbalanced operation, in that it leaves one more value in the stack than it started with. If it doesn't have a left-hand value pairing, the compiler shouldn't use an implied push.

Function calls appear in one of two places, within an expression, or as a standalone invocation. If they appear within an expression, the final left-handed member of the expression will always appear at the bottom of the instruction queue. If they appear as a stand alone expression, they simply stand alone.

To put it more simply, a function can't return its value until it has been 1) scheduled, and 2) executed by the scheduler. The variable cannot be assigned until every operation of the right-hand expression is solved.


As always, whenever we interact, I strongly recommend looking over a tutorial. How functions/arguments/variables work isn't an advanced topic, it's first-paragraph material, and any confusion means you are lacking in core concepts that you really need to understand to move forward.
mob
verb
Go()
var/s = startup('Test.dmb',6666)
usr << link("byond://[s]")


Tested this doesn't work. Am I missing something?
My guess would be that the new world isn't accepting connections because it hasn't been given enough time to start up. Give something like this a shot. We try to ping the world repeatedly until either 30 attempts elapses, or we succeed in pinging the child server.

proc
childWorld(dmb,port=0)
if(port)
. = startup(dmb,port)
else
. = startup(dmb)
var/attempts = 0
var/res = 1
while(attempts++ < 30)
res = world.Export("byond://[.]?ping")
if(res)
return .
return null
Alright it returns 1/true right away. So...

mob
verb
Go()
childWorld('Test.dmb',6666)

usr << link("byond://127.0.0.1:6666")


And, Nothing so I assume the issue is somewhere else. Let's go searching.
Can you upload your projects? Also post version number of BYOND. There was a recent world.Export() issue...maybe related?
childWorld doesn't return 1. I suspect you are mistaken, and there is literally nothing else to explore.
6666
IF port
AN ATTEMPT
1
RES = 1
DEFAULT = 10.59.1.51:6666


Sorry res is 1. The procedure returns default address.

mob
proc
childWorld(dmb,port=0)
world << dmb
world << port
if(port)
world << "IF port"
. = startup(dmb,port)
else
world << "ELSE"
. = startup(dmb)
var/attempts = 0
var/res = 1
while(attempts++ < 30)
world << "AN ATTEMPT"
res = world.Export("byond://[.]?ping")
world << world.Export("byond://[.]?ping")
if(res)
world << "RES = [res]"
world << "DEFAULT = [.]"
return .
world << "return null"
return null
mob
verb
Go()
childWorld('Test.dmb',6666)

spawn(80) usr << link("byond:10.59.1.5:6666")



5.0 Beta 506.1241
Page: 1 2