Question About The New World System
Heya there,
I was just looking into the new "world" system and I had a question.
I was wondering how you would do a world system in which you could join it with just a name rather then the number too (showed in the example).
Thanks
Replies (4)
Last message on 28 Dec 2017
Size43
(Administrator)
on
28 Dec 2017, 10:25:05
By world/session "name" is easy. Just change the code in obj_world_select, <Enter> to this:
var name = keyboard_string
var existingSession = find_session_with_tag(1, name)
if existingSession != -1
{
gms_session_join(existingSession)
} else {
var index = get_integer("Enter a world index: ", 0)
gms_session_create_ext(st_world, string(index) + '|' + string_lettersdigits(name))
}
By player name would require the use of p2p messages to find out in which session the player is. Something like this:
1. A broadcasts p2p_where_are_you(arguments: 'Size43') to gms_p2p_all_in_game
2. Size43 receives message, and confirms that the argument is his name
3. Size43 sends p2p_i_am_here(arguments: gms_session_current_id()) to A
4. A receives message, and joins the session ID they received
Size43
(Administrator)
on
28 Dec 2017, 10:35:30
One small remark: this doesn't check whether there's already a session that's loaded the world index! So you could have two sessions working on the same world, overwriting each other's changes.
You should add an if check after get_integer to make sure there's no session already playing that world:
if find_session_with_tag(0, string(index)) == -1
{
// No session for this world yet! Create a new one
} else {
// Show error
}
You could take this one step further, and store world names in the GameINI so people never have to enter a world index.
ConnorDEV
(Topicstarter)
on
28 Dec 2017, 10:39:18
Ah, I see.. Thanks :)
P.S. Is there anyway to remove entering the index as a whole so you only input a world name, similar to a game like Growtopia.
Size43
(Administrator)
on
28 Dec 2017, 10:58:59
Like I mentioned, you'd have to save the world names in the GameINI and look them up when someone enters a world name. However note that you only have a limited number of BDB indices, so you'd have to set a limit somewhere.