[Snippet] Additional Vars

Ninja FTW

Well-Known Member
Joined
Aug 11, 2017
Messages
61
Likes
0
Points
6
Location
Saturn
#1
I just stumped upon Deji's SuperVars and this was mentioned in readme

I originally created the script 'ExtraVars' which demonstrated
a way to extend the limitations on variable usage by directly  
accessing memory using var arrays. A little example:
   1@(31@,1i)

...

However, this method wasn't without fault. I started noticing  
crashes caused by the index falling to certain values and      
causing the game to write to a bad section of memory.
I don't know what exactly it's means 

but i make a quick test by trying make 1024 additional vars and found no problem. So, i've decided to share this. Might come in handy for coders. Removing limitations of vars

Code:
0A90: [email protected] = 4 * 1024 // int
0AC7: [email protected] = var [email protected] offset            // get the pointer to the last usable variable
0AC8: [email protected] = allocate_memory_size [email protected]
0A8F: [email protected] = [email protected] - [email protected]                // get the offset from variable [email protected] to the memory
0016: [email protected] /= 4                      // divide by array size to get the index
0085: [email protected] = [email protected] // (int)
0006: [email protected] = 0
0006: [email protected] = 0    
//fill extra var [email protected]([email protected],4i) - [email protected]([email protected],4i)
for [email protected] = 0 to 1023 step 1
    0A90: [email protected] = [email protected] * 2 // int
    0085: [email protected]([email protected],4i) = [email protected] // (int)   
    0AD1: show_formatted_text_highpriority "[Offset: %d]~n~[%[email protected]: %d]" time 500 [email protected] [email protected] [email protected]([email protected],4i)
    wait 0
    000A: [email protected] += 1
end
//compare variable and value
while true
    wait 0
    0AD1: show_formatted_text_highpriority "[Offset: %d]~n~[[email protected]: %d][[email protected]: %d][[email protected]: %d]~n~[[email protected]: %d][[email protected]: %d][[email protected]: %d]~n~[[email protected]: %d][[email protected]: %d]" time 2000 [email protected] [email protected]([email protected],4i) [email protected]([email protected],4i) [email protected]([email protected],4i) [email protected]([email protected],4i) [email protected]([email protected],4i) [email protected]([email protected],4i) [email protected]([email protected],4i) [email protected]([email protected],4i)
end
 
OP
OP
Ninja FTW

Ninja FTW

Well-Known Member
Joined
Aug 11, 2017
Messages
61
Likes
0
Points
6
Location
Saturn
#4
Problem is:

if the same variable found in a script then i think they might crash the game by colliding with each other. The best solution is to simulate two FUNC like 0AB3 and 0AB4 but remember for our MEmoryThread


Code:
{ something like in programming languages , the comment at the end of the function label
will be printed on the list of labels that 
Sanny generates when you begin typing one. It will also be placed
in the editor when you select it from that list. 
Just a simple little thing to remind you what the function does 
and how many parameters it uses.}

:set{passed_value,var_number,var_size}  
0AC6: [email protected] = get_label_pointer @memory
int [email protected] *= 4   //you can put a typedef in some cases before a variable instead of typing the opcode of that operation.
int [email protected] += [email protected]
Memory.Write([email protected],[email protected],[email protected],0)
ret 0

:get{var_number,var_size}
0AC6: [email protected] = get_label_pointer @memory
int [email protected] *= 4
int [email protected] += [email protected]
[email protected] = Memory.Read([email protected],[email protected],0)
ret 1 [email protected]

:memory  // extra vars , whatever number of vars you like... the only limit is your RAM.
hex
00 00 00 00  // var 0
00 00 00 00  // var 1
00 00 00 00  // var 2
00 00 00 00  // var 3
00 00 00 00  // var 4
00 00 00 00  // var 5
00 00 00 00  // var 6
00 00 00 00  // var 7
00 00 00 00  // var 8
00 00 00 00  // var 9
00 00 00 00  // var 10
00 00 00 00  // var 11
00 00 00 00  // var 12
00 00 00 00  // var 13
00 00 00 00  // var 14
00 00 00 00  // var 15
00 00 00 00  // var 16
00 00 00 00  // var 17
00 00 00 00  // var 18
00 00 00 00  // var 19
00 00 00 00  // var 20
00 00 00 00  // var 21
00 00 00 00  // var 22
00 00 00 00  // var 23
00 00 00 00  // var 24
00 00 00 00  // var 25
00 00 00 00  // var 26
00 00 00 00  // var 27
00 00 00 00  // var 28
00 00 00 00  // var 29
00 00 00 00  // var 30
end
Here's an example of using:


Code:
{$CLEO}

0000:

// some examples

[email protected] = 5
0AB1: @set 3 passed_value [email protected] var_number 0 var_size 4  // value of [email protected] is stored in var 0 

0AB1: @get 2 var_number 3 var_size 4 receiver [email protected] // value of  var 3 is received in [email protected]

[email protected] = 4
0AB1: @set 3 passed_value [email protected] var_number 2 var_size 4  // value of [email protected] is stored in var 2

0AB1: @get 2 var_number 30 var_size 4 receiver [email protected] // value of  var 30 is received in [email protected]

{ in case of passing integer variables like [email protected] then var_size must be always 4 bytes  
, @s  strings are 8 bytes ( 2 vars)
, @v  long strings are 16 bytes (4 vars )
so it's just like Cleo variables when you use [email protected] , 
you know that [email protected],[email protected],[email protected] will be used to store the 16 bytes value}



for [email protected] = 0 to 30
    0A90: [email protected] = [email protected] * 2 // int // the value is variable index * 2
    0AB1: @set 3 passed_value [email protected] var_number [email protected] var_size 4 // storing value of [email protected] to variables starting from var0 to var30   
end


while not key.Pressed(0x54)
wait 0
end

for [email protected] = 0 to 30
    wait 500
    0AB1: @get 2 var_number [email protected] var_size 4 receiver [email protected]
    0ACE: print_help_formatted "Value of var %i is %i" [email protected] [email protected]     
end               

end_custom_thread
 
OP
OP
Ninja FTW

Ninja FTW

Well-Known Member
Joined
Aug 11, 2017
Messages
61
Likes
0
Points
6
Location
Saturn
#8
@0B36 - Keep PMing, little boy. I'm not stupid and idiot like you who is going to fight with a baby. Go and observe at the rules, once again.

 

Husnain

Well-Known Member
Joined
May 20, 2016
Messages
175
Likes
0
Points
16
Location
Mars
#9
@Nin FTW - He's mentally disordered and racist. Just ignore him. Someone did not told him that how appreciation is a real thing.

Edit: This shit really rocks with upto [email protected] variables xd.
 
Top