I'm working on a 2D Sidescrolling Sandbox game and I was wondering how you could create a new server or "world" when ever a player joins using that players name.
For example, when the player joins the game, it makes a session with what ever that players name is, and anyone else can join that "world" by typing it into a text box.
I've looked into sessions but I find it a little tricky
Thanks.
Replies (6)
Last message on 5 Nov 2017
Size43
(Administrator)
on
28 Oct 2017, 10:50:29
You'd have to store the session / player names in the GameINI. Sessions cannot be named, and only have a session ID.
Size43
(Administrator)
on
28 Oct 2017, 11:17:49
To give a general idea of how this would look:
When creating a session you store the ID in the GameINI:
gms_ini_game_write("sessions", gms_self_name(), gms_session_current_id())
Note that you cannot do this directly after calling gms_session_create(...) since it takes a few seconds before the session ID updates.
...and when someone else enters a name you load that session ID back:
var target_session;
target_session = gms_ini_game_read("sessions", "THE_NAME_ENTERED")
if gms_session_exists(target_session)
{
gms_session_join(target_session)
} else {
show_message("Session no longer available")
}
You should probably delete the stored ID from the INI when the player disconnects using
gms_ini_game_delete
ConnorDEV
(Topicstarter)
on
28 Oct 2017, 17:35:52
Or I belive the part i'm stuck on is using "gms_session_create"
Size43
(Administrator)
on
5 Nov 2017, 11:28:21
ConnorDEV
(Topicstarter)
on
28 Oct 2017, 17:06:32
Hey there, just got your reply. Thanks for the help.
I'm sort of understanding the just, apart from one part.
I was hoping to make the "worlds" more permanent and from what i'm understanding, calling
gms_ini_game_write("sessions", gms_self_name(), gms_session_current_id())
uses the same session ID each time
Size43
(Administrator)
on
5 Nov 2017, 11:27:30
Unfortunately, GameMaker Server does not have a good way to create permanent worlds (like minecraft, where many things are user-placeable). When there are no players in a session, it is destroyed.
You might be able to replicate something like this using P2P messages, but that's pretty difficult.
I'm planning to add better support for this use-case in the rewrite. Unfortunately, as I stated before development for the rewrite is delayed indefinitely until my hand heals.