Legacy GM [SOLVED] variable = function

Z

Zagmojo

Guest
I'm beginning my endeavor into networking and have been coming across many a code containing something I don't entirely understand and have been unsuccessful in finding a definitive answer to. When defining a variable as a function, what is it being set to? Is it coming up with a value that I'm overthinking or is it legitimately existent?
An example is:

server = network_create_server_raw(network_socket_tcp, port, 20);

I don't understand what server is being set to in this case.

I also have a follow up question if and when this is resolved. It has to do with data structures (another key aspect of gamemaker I still don't understand even after hours on end of watching tutorials and reading forums) and how their recalled. The reason I bring it up in this thread specifically is due to the data structures often being set to varibales which, again, I don't comprehend.

Thanks for any and all help!
 

CloseRange

Member
@Zagmojo
https://docs.yoyogames.com/source/dadiospice/002_reference/networking/network_create_server_raw.html
if you look at the documents for any function in game maker it will say Returns: followed by the return value. the network_create_server returns a real meaning a number (1, 2, 3, 4, 5 ect.)
string is a series of characters: "A B C D e f g - # %"
and bool is true or false (aka 1 and 0)

if you went to the draw event and said:
Code:
draw_text(0, 0, server);
it would just draw a number

if you did:
Code:
var_sprite = sprite_index;
it is storing a number, this number means nothing to you but it is used as a pointer id that points to the id of your sprite_index.
If you said:
Code:
sprite_index = 0;
your sprite index would be set to the first sprite that have at the very most top of your recourse tree.
these values are usually defaulted at some negative number and that can be useful because if you said:
Code:
if server >= 0 {

}
well now you can check if the server was created.

I'm not too good with DS maps but I know they probobly work the exact same way.
Computers can only read numbers, even strings are, in reality, just numbers.
If you said:
Code:
var text = "Hello World";
draw_text(0 ,0, real(text));
you would probably find a weird number because strings are just numbers converted to characters (think of you and your friend having a secret language where you took numbers and said like: 26 is E and 27 is F and 28 is G)
in fact you could see this "secret code" if you just search up ascii chart.


The bottom line is the variable just gives a number that servers as a pointer to reference what object, sprite, server, or ect you are calling.
 
Z

Zagmojo

Guest
@Zagmojo
https://docs.yoyogames.com/source/dadiospice/002_reference/networking/network_create_server_raw.html
if you look at the documents for any function in game maker it will say Returns: followed by the return value. the network_create_server returns a real meaning a number (1, 2, 3, 4, 5 ect.)
string is a series of characters: "A B C D e f g - # %"
and bool is true or false (aka 1 and 0)

if you went to the draw event and said:
Code:
draw_text(0, 0, server);
it would just draw a number

if you did:
Code:
var_sprite = sprite_index;
it is storing a number, this number means nothing to you but it is used as a pointer id that points to the id of your sprite_index.
If you said:
Code:
sprite_index = 0;
your sprite index would be set to the first sprite that have at the very most top of your recourse tree.
these values are usually defaulted at some negative number and that can be useful because if you said:
Code:
if server >= 0 {

}
well now you can check if the server was created.

I'm not too good with DS maps but I know they probobly work the exact same way.
Computers can only read numbers, even strings are, in reality, just numbers.
If you said:
Code:
var text = "Hello World";
draw_text(0 ,0, real(text));
you would probably find a weird number because strings are just numbers converted to characters (think of you and your friend having a secret language where you took numbers and said like: 26 is E and 27 is F and 28 is G)
in fact you could see this "secret code" if you just search up ascii chart.


The bottom line is the variable just gives a number that servers as a pointer to reference what object, sprite, server, or ect you are calling.
Okay! I didn't actually realize that's what "returns:" was for, good to know. Your reply was definitly very helpful for the first question, so thank you!

As far as creating a ds_map, when one sets a variable (for example) var_mymap = ds_map_create(); what exactly is it setting var_mymap to? I don't mean to sound repetitive, I just don't quite understand.
 

Paskaler

Member
If it's the first ds_map you create it's going to return a 0. GameMaker stores a list of all of the ds_* (any data structure (list, map, stack, ...)) in a list internally. So when you do something like:

Code:
var_mymap = ds_map_create();
var_mymap[?"mykey"] = 0;
GameMaker is going to go into it's list of ds_maps it has stored, look for the one at the index of var_mymap. In this case it would be 0 if it's the first one created. Then it will add a key called mykey and set it's value to 0.
So, basically, all of the ds_*_create() functions return an index in an internal list of that specified type of data structure.

Same goes for using instance_create, the difference being that instance_create returns indices starting from 100000.

Another important thing to note is that GameMaker recycles indices when they are no longer used. So when you do ds_map_destroy(var_mymap) index of 0 will be free again and the next ds_map that you create will be at index 0 once more.

You could do(I don't see the reason why you would, tough):
Code:
var_mymap = ds_map_create();
var_mymap[?"mykey"] = 0;
var pointer_to_mymap = 0;
pointer_to_mymap[?"mykey1"] = 0;
var another_pointer = var_mymap;
another_pointer[?"mykey2"] = 0;
var_mymap, pointer_to_mymap and another_pointer will all modify the same ds_map. Again, I'm assuming that this map is the first one created
 
Z

Zagmojo

Guest
If it's the first ds_map you create it's going to return a 0. GameMaker stores a list of all of the ds_* (any data structure (list, map, stack, ...)) in a list internally. So when you do something like:

Code:
var_mymap = ds_map_create();
var_mymap[?"mykey"] = 0;
GameMaker is going to go into it's list of ds_maps it has stored, look for the one at the index of var_mymap. In this case it would be 0 if it's the first one created. Then it will add a key called mykey and set it's value to 0.
So, basically, all of the ds_*_create() functions return an index in an internal list of that specified type of data structure.

Same goes for using instance_create, the difference being that instance_create returns indices starting from 100000.

Another important thing to note is that GameMaker recycles indices when they are no longer used. So when you do ds_map_destroy(var_mymap) index of 0 will be free again and the next ds_map that you create will be at index 0 once more.

You could do(I don't see the reason why you would, tough):
Code:
var_mymap = ds_map_create();
var_mymap[?"mykey"] = 0;
var pointer_to_mymap = 0;
pointer_to_mymap[?"mykey1"] = 0;
var another_pointer = var_mymap;
another_pointer[?"mykey2"] = 0;
var_mymap, pointer_to_mymap and another_pointer will all modify the same ds_map. Again, I'm assuming that this map is the first one created
Thank you sooo much! I understand this much better now!
 
Top