funtikar Posted March 9, 2012 Share Posted March 9, 2012 (edited) OK In another thread I would store $PLAYER_CHAR's money to a variable and pass it to a thread something like this 010B: [email protected] = player $PLAYER_CHAR money0A92: create_custom_thread "statsave.s" [email protected] Then this thread will receive it and store it into a file but the problem is I don't know how much byte has the variable taken. I don't know what to put for the size of bytes. As you can see I replaced the size of bytes with a hash. {$VERSION 3.1.0027}{$CLEO .cs}//-------------MAIN---------------name_thread "statsave"wait 100:statsave_10A9A: [email protected] = openfile "CLEO/stats.dat" mode 0x6277 // write binary mode0A9E: writefile [email protected] size # from [email protected]: closefile [email protected]_thread Edited March 9, 2012 by funtikar Link to comment Share on other sites More sharing options...
DK22Pac Posted March 9, 2012 Share Posted March 9, 2012 1 var = 4 bytes. Link to comment Share on other sites More sharing options...
funtikar Posted March 9, 2012 Author Share Posted March 9, 2012 Darn it, I was confused . I thought FF FF was four bytes. since FF FF would only fit 65535 money.. ok problem solved... Link to comment Share on other sites More sharing options...
Ashwin.Star Posted March 9, 2012 Share Posted March 9, 2012 if you want to pass it to another thread then you should use global variables! Link to comment Share on other sites More sharing options...
funtikar Posted March 9, 2012 Author Share Posted March 9, 2012 thanks for informing that . I've just started learning Link to comment Share on other sites More sharing options...
Deji Posted March 9, 2012 Share Posted March 9, 2012 if you want to pass it to another thread then you should use global variables! No, he shouldn't. Link to comment Share on other sites More sharing options...
Ashwin.Star Posted March 10, 2012 Share Posted March 10, 2012 why deji, i think local variables remain only in thread limits, Link to comment Share on other sites More sharing options...
OrionSR Posted March 10, 2012 Share Posted March 10, 2012 The best practice when writing CLEO scripts is to avoid using global variables except for a few special global variables like $ONMISSION, $PLAYER_CHAR, and $PLAYER_ACTOR. Technically, global variables should work just fine in CLEO scripts, but if you are not very careful then you will overwrite values used by the game, or the game will overwrite your values when CJ engages in certain activities or missions. Even if you are very careful, if you use mods from other players, or try to share your mods with others, there is no way to anticipate which global variables might be used in other scripts. Worse yet, if custom global variable names are used then there is a good chance your script will conflict with the main.scm AND other CLEO scripts. Link to comment Share on other sites More sharing options...
Deji Posted March 10, 2012 Share Posted March 10, 2012 (edited) Not 'special' global variables, as such. But Sanny must be able to match the global var name with an offset defined in CustomVariables.ini. If it doesn't match an entry, it uses an entry which doesn't exist in the list. For me, compiling: $blah = 0$blah2 = 0 Decompiled as: $1557 = 0$1558 = 0 The resulting offsets may be different for other people (I've messed with my CustomVariables.ini) but people with matching CustomVariables.ini (CustomArrays.ini probably matters as well - my version of the file is empty) files will most likely result in the same number, resulting in conflict. But regardless, he doesn't even need global variables. He's correctly passing values to the new script here: 0A92: create_custom_thread "statsave.s" [email protected] Edited March 10, 2012 by Deji Link to comment Share on other sites More sharing options...
funtikar Posted March 10, 2012 Author Share Posted March 10, 2012 ahhh okay Link to comment Share on other sites More sharing options...
Ashwin.Star Posted March 11, 2012 Share Posted March 11, 2012 @deji i know that, this is the reason when i use global var in any cleo script, i use numbers only, begins with $9000 onwards as vc main scm Gvar not exceed than that, Link to comment Share on other sites More sharing options...
Link2012 Posted March 11, 2012 Share Posted March 11, 2012 (edited) @dejii know that, this is the reason when i use global var in any cleo script, i use numbers only, begins with $9000 onwards as vc main scm Gvar not exceed than that, In fact this variables doesn't exist, but the space that they writes continues going from the last var (The var $0 is write in the first byte of the main.scm, $1 in fifth byte...), the second segment is the models data, the third the mission defs and obviosly then the code segment. So, you're overwriting main.scm information, depending on the variable number you're overwriting the Models defs/, Missions defs or the Code segment, Still overwriting important informations The situation worsens if the user is using a TC or a stripped main, because the var seg/models defs/missions defs is shorter, so the code segment is very easily overwritable (or the things after the code...). Edited March 20, 2012 by Link2012 Link to comment Share on other sites More sharing options...
Deji Posted March 11, 2012 Share Posted March 11, 2012 @dejii know that, this is the reason when i use global var in any cleo script, i use numbers only, begins with $9000 onwards as vc main scm Gvar not exceed than that, But other CLEO scripts or a modified MAIN could use the same variables. It's much better practise to simply not use them. Link to comment Share on other sites More sharing options...
Ashwin.Star Posted March 20, 2012 Share Posted March 20, 2012 In fact this variables doesn't exist ohh, please tell me how many VAR exist then The var $0 is write in the first byte of the main.scm, $1 in fourt byte... ha ha ha, i am laughing on your intelligence, if you are right then i can make a cleo script which can Modify you main.scm, you're overwriting main.scm information i am using a Global VAR which is not used in SCM, okay, overall, please have some TUT & learn more about Variables, Link to comment Share on other sites More sharing options...
Link2012 Posted March 20, 2012 Share Posted March 20, 2012 (edited) Noob, you that need to learn some more about SCM at low level, do you think these tutoriais that you learned explains how the things works inside? No, you need to learn by yourself. Open main.scm with a hex editor and see the global variables space, all with zeros. You like this website, so take a look to VC main.scm structure: http://www.gtamodding.com/index.php?title=VC_SCM Edited March 20, 2012 by Link2012 Link to comment Share on other sites More sharing options...
Ashwin.Star Posted March 20, 2012 Share Posted March 20, 2012 Try your self what i said, and tell me if you got any problem, okay. i don't want to fight with you, lol, ------------------------------------------ belated happy 14th birthday to you LINK, Link to comment Share on other sites More sharing options...
Link2012 Posted March 20, 2012 Share Posted March 20, 2012 Ok ashwin, I will not continue with it. I argued and you not, I show you the way to see the truth and you couldn't see it... Or you want to continue ignorant or you couldn't admit that was wrong. belated happy 14th birthday to you LINK, THANKS! Link to comment Share on other sites More sharing options...
fastman92 Posted March 20, 2012 Share Posted March 20, 2012 Link2012 is right here Link to comment Share on other sites More sharing options...
Ashwin.Star Posted March 20, 2012 Share Posted March 20, 2012 @Link Your welcome, @fastman just tell me one thing, if $9000+ are not used in scm, then why will it overwrite anything in SCM ? Link to comment Share on other sites More sharing options...
Silent Posted March 20, 2012 Share Posted March 20, 2012 @fastmanjust tell me one thing, if $9000+ are not used in scm, then why will it overwrite anything in SCM ? You can't be sure if any custom SCM uses it. Link to comment Share on other sites More sharing options...
fastman92 Posted March 20, 2012 Share Posted March 20, 2012 (edited) Think it over. $2 - 4 bytes, int or float, handle - any number s$2 - 8 bytes, short string Capacity of 7 chars v$2 - 16 bytes, long string. Capacity of 15 chars. There is reserved, limited memory space for global variables: .data:00A49960 ; char scmBlock[].data:00A49960 _scmBlock db 200000 dup(?) ; 0; DATA XREF: _sub_44CA40+2r Capacity of 0x00A49960 depends on http://www.gtamodding.com/index.php?title=SA_SCM 32 bit int Size of global var space The next thing after variables on scmBlock is mission code. You're overwritting mission code, because you run out of space defined by 32 bit int Size of global var space in main.scm If you have a trouble with amount of local variables and some more: :getAdditionalVarsLabelPointedIndex{Description: Calculates array index pointing to label Parameters: Passed: [email protected] - label [email protected] - divider Result: [email protected] - index, movement Example: 0AB1: call_scm_func @getAdditionalVarsLabelPointedIndex 2 label @AdditionalVariables divider 4 store_index_to [email protected] :AddtionalVariables hex 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 // alignment 00 00 00 00 // [email protected] 00 00 00 00 // [email protected] end Usage in code: [email protected]([email protected],1i); [email protected]([email protected],1i) and so on}0A9F: [email protected] = [email protected] += 60 // [email protected] adress0A9F: [email protected] = [email protected] += 0x100A8D: [email protected] = read_memory [email protected] size 4 virtual_protect 00062: [email protected] -= [email protected] // (int) @label adress0062: [email protected] -= [email protected] // (int) [email protected] pointer - @label [email protected] /= [email protected] += [email protected] *= 160072: [email protected] /= [email protected] // (int)0AB2: ret 1 [email protected] You should know how to use this. Edited March 20, 2012 by fastman92 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now