Windows [Solved] - Global Var doesn´t have the actual value

Ecoo

Member
[Edit]
is it possible that gm alrady have a variable called exp or global.exp?

Thx to [USER=50928]saffeine[/USER] to confirm it.
" the exp() function has an index of 206 ( if you type a function name without the parenthesis it returns the index rather than calling it "
[/Edit]

Hi there,

i have a confused issue.

here my code:
scr_revice_msg()
GML:
...
            case 7:
                var player = buffer_read(buffer, buffer_u16);
                scr_get_states(player, 1);
                scr_server_send_data(1, targetsocket, 7, global.exp);
                break;
            case 8:
...
scr_server_send_data()
GML:
    var send_typ = argument0,
        targetsocket = argument1,
        sending = argument2,
        num_u16 = argument3,
        num_u32 = argument4,
        str = argument5,
        buffer = buffer_create(1024, buffer_grow, 1);
    ...
        case 1:
            show_debug_message("senden 1");
            buffer_seek(buffer, buffer_seek_start, 0);
            buffer_write(buffer, buffer_u8, sending);
            buffer_write(buffer, buffer_u16, num_u16);
            network_send_raw(targetsocket, buffer, buffer_tell(buffer));
            break;
        case 2:
    ...
here we go:

i run with the debuger and this heppend every time
after line "scr_get_states(player, 1);" my global.exp has a value of 406. It was before at 206. in the next step it have the pointed 406 and go to "scr_server_send_data" with (1, targetsocket, 7, global.exp). but in the next step in "scr_server_send_data" argument3 got the value of 206.
debug global variable says global.exp is 406 in all this 3-4 steps. i dont get it why argument3 get this old value.
i have around 20 global variable and all of them working correct.

i think this is be a issue with a pointer or smt like that but i cant see it.
 
Last edited:

samspade

Member
Are you saying that if you step through the code line by line on this line, scr_server_send_data(1, targetsocket, 7, global.exp); the debugger says global.exp equals 406, but that when you step into that function argument3 shows the value 206 after the very next step (immediately upon stepping into that function)?

That is not what I would expect. I have a couple questions:
  • Which version of GM are you using?
  • Why does the code you posted for scr_server_send_data use 6 arguments but the prior code only passes in 4?
  • Have you tried using named arguments?
  • What does scr_get_states look like?
 

Ecoo

Member
Are you saying that if you step through the code line by line on this line, scr_server_send_data(1, targetsocket, 7, global.exp); the debugger says global.exp equals 406, but that when you step into that function argument3 shows the value 206 after the very next step (immediately upon stepping into that function)?
absolutly correct!

[edit]
btw the var global.exp is still 406 all the time till i destroy its instance. Only the argument3 get value 206. how and from where... idk.
[/edit]


Which version of GM are you using?
IDE-Version 2.3.2.560
actuel runtime 2.3.2.426

Why does the code you posted for scr_server_send_data use 6 arguments but the prior code only passes in 4?
because i need scr_server_send_data for more operations, with variable argument_couts.

What does scr_get_states look like?
scr_get_states()
GML:
function scr_get_states(argument){
    var dir = argument0;
    var dir1 = argument1;
   
    if (argument_count == 2){
        ini_open(string(dir) + ".ini");
       
        ...
       
        global.exp = ini_read_real("states", "exp", 0);
       
        ...
       
        ini_close();
    }
}
Have you tried using named arguments?
like what? here is the first line at the scr_server_send_data
function scr_server_send_data(argument){
 
Last edited:

chamaeleon

Member
scr_get_states()
GML:
function scr_get_states(argument){
    var dir = argument0;
    var dir1 = argument1;
 
    if (argument_count == 2){
        ini_open(string(dir) + ".ini");
     
        ...
     
        global.exp = ini_read_real("states", "exp", 0);
     
        ...
     
        ini_close();
    }
}
like what? here is the first line at the scr_server_send_data
function scr_server_send_data(argument){
More like asking if you have tried
GML:
function scr_get_states(dir, dir1) {
    ...
}
and not refer to old-style argument variables at all in your code, just use the named arguments provided in the function definition. If you really need to protect against not having all arguments available, you can always check if dir and/or dir1 are undefined using is_undefined().
 

samspade

Member
I would try using named arguments. While you should be able to use the old argument keywords, you might be running into an issue if you are using them while using a variable amounts of arguments. Prior to 2.3, you could only use the keywords argument0...argument15 if you had a fixed number of arguments. You would use the argument array for functions with a variable amount of arguments. (I'm not even sure GM would compile if you used the argument0 keywords but provided a different amount of arguments, though it's been awhile now.)

I've never actually used the argument0...15 keywords in 2.3, and I don't know why using them in this way would cause this error, but it would be something to test.

I'm also surprise this works:

GML:
function scr_get_states(argument){
    var dir = argument0;
    var dir1 = argument1;
    ...
}
Even if it does, it probably shouldn't. argument is a keyword and refers to the argument array. I'm no sure if anything bad happens when you use it that way, but @chamaeleon's example is the correct form.
 

Ecoo

Member
ok first at all u both are right. @chamaeleon's example is correct but i need in that funktions "not" fixed number of arguments. and in that form i get only syntax errors. but this is not the question. because in that funktion scr_get_stats is all fine. all my Variables get the right value, even global.exp. here i have a screen for u, where i use the debuger.

.. ok i cant, need to contact an admin first.

lets try it this way:

GML:
line 77:            case 7:
line 78:                var player = buffer_read(buffer, buffer_u16);
line 79:                scr_get_states(player, 1);
line 80:                show_debug_message(global.exp);
line 81:                scr_server_send_data(1, targetsocket, 7, global.exp);
line 82:                break;
line 83:            case 8:
if i hover exp after line 79 the debugger show me a value of 406.
in Variables - > global -> exp shows me a value of 406.
BUT if i creat a own watch with the variable global.exp its show me the value of 206.
and in line 81 i get a debug message of 206.
and in line 82 its jump to scr_server_send_data with the value of 206.

i have only 1 Vaiable called global.exp. and its rly confused that a get by mouse hover and the Global-Tap from debuger the value 406 but if i rightklick this global.exp and add a watch i get a variable with global.exp and a value of 206. (i didnt add a watch by manual writing!)


PS. i tryed "the correct form" with:
Code:
function scr_server_send_data(send_typ, targetsocket, sending, num_u16, num_u32, str){
    /*var send_typ = argument0,
        targetsocket = argument1,
        sending = argument2,
        num_u16 = argument3,
        num_u32 = argument4,
        str = argument5,
        buffer = buffer_create(1024, buffer_grow, 1);*/
        var buffer = buffer_create(1024, buffer_grow, 1);
and
Code:
function scr_get_states(dir, dir1){
    //var dir = argument0;
    //var dir1 = argument1;
its the same result... :(
i got only some syntax errors with: "this need 6 arguments but got only 4"

[edit]here is the screenshot[/edit]
screen.png
 
Last edited:

Ecoo

Member
ok guys i have there sonething... i think so.

is it possible that gm alrady have a variable called exp or global.exp?
i tried a lot of stuff and startet the debuger at point zero. bevor my initial variables are loadet.
in the debuger shows a variable exp or/and global.exp with the value of 206.
All other variables are undefined.
but the only think i can find is the funktion exp() and litaraly no other variables. except in the debugger.
can someone comfirm this?
 

saffeine

Member
ok guys i have there sonething... i think so.

is it possible that gm alrady have a variable called exp or global.exp?
i tried a lot of stuff and startet the debuger at point zero. bevor my initial variables are loadet.
in the debuger shows a variable exp or/and global.exp with the value of 206.
All other variables are undefined.
but the only think i can find is the funktion exp() and litaraly no other variables. except in the debugger.
can someone comfirm this?
that'll probably be your issue in that case. all functions are assigned an index, and in this particular instance, the exp() function has an index of 206 ( if you type a function name without the parenthesis it returns the index rather than calling it ).
i just checked in an empty project and sure enough it's the same value you're getting. i think the only thing you can really do is change the name of the variable, even if it's just adding an extra letter, so long as it doesn't overlap with the name of any other resource in the project of course :p

1621432915655.png
 
Top