Scripting / Coding Question

GPC2 script programming for Titan Two. Code examples, questions, requests.

Re: Scripting / Coding Question

Postby jelly44 » Fri Sep 06, 2019 11:23 am

Thanks, Scachi. Will be testing it.
- My recommendation for learning C programming: 'C Programming Absolute Beginner's Guide'
- Create your own scripts with GPC2 Scripting
User avatar
jelly44
Sergeant Major of the Army
Sergeant Major of the Army
 
Posts: 220
Joined: Tue Feb 05, 2019 3:49 pm

Re: Scripting / Coding Question

Postby Prototype » Sat Sep 07, 2019 8:16 pm

Thank you scachi for the fix16 (fix32 bitsize 16). I didn't know that, it's very useful!
Console tuner since my 1st controller.
Scripting, a game in the game.
Believe or dare, It's Titanic! :smile0517:
User avatar
Prototype
Major General
Major General
 
Posts: 3252
Joined: Sun Dec 16, 2012 1:43 pm

Re: Scripting / Coding Question

Postby jelly44 » Wed Sep 11, 2019 9:27 am

prototype wrote:Thank you scachi for the fix16 (fix32 bitsize 16). I didn't know that, it's very useful!

That is indeed good to know - now I understand what it means. If I use it right, I can halve the size of my interactive configuration menu.

Just a recap, I do the below for each of the variables I want to reduce its size:

Code: Select all
 fix32  StickNoise;
 
init {
    pmem_load();
StickNoise = pmem_read_int16tofix32(1); // read "fix16" value from byteoffset 1
} 


Then add the following code, right?

Code: Select all
 // read fix16 from pmem position ( read int16 and return it as fix32 )
fix32 pmem_read_int16tofix32 (uint8 pmem_location) {
  int16 valInt16;
  pmem_read(pmem_location, &valInt16);
  return (fix32)valInt16 / 256.0;
}
 
- My recommendation for learning C programming: 'C Programming Absolute Beginner's Guide'
- Create your own scripts with GPC2 Scripting
User avatar
jelly44
Sergeant Major of the Army
Sergeant Major of the Army
 
Posts: 220
Joined: Tue Feb 05, 2019 3:49 pm

Re: Scripting / Coding Question

Postby Scachi » Wed Sep 11, 2019 9:50 am

Yes. Something like this:
Code: Select all
 
fix32  fx16_A, fx16_B, fx16_C, fx16_D, ...;
 
init {
    pmem_load();
    fx16_A = pmem_read_int16tofix32(1); // read "fix16" value from byteoffset 1
    fx16_B = pmem_read_int16tofix32(3); // read "fix16" value from byteoffset 3
    fx16_C = pmem_read_int16tofix32(5); // read "fix16" value from byteoffset 5
    .
    .
    .
}
 
 // read fix16 from pmem position ( read int16 and return it as fix32 )
fix32 pmem_read_int16tofix32 (uint8 pmem_location) {
  int16 valInt16;
  pmem_read(pmem_location, &valInt16);
  return (fix32)valInt16 / 256.0;
}
 
 

But keep in mind your min/max values of this fix32 16bit is around -127.nn to 127.nn
If you need higher values as decimals you have to stick to fix32 32bit.
User avatar
Scachi
Brigadier General
Brigadier General
 
Posts: 3044
Joined: Wed May 11, 2016 6:25 am
Location: Germany

Re: Scripting / Coding Question

Postby jelly44 » Wed Sep 11, 2019 9:52 am

thanks Scachi. It works perfectly for the anti recoil values between -100.00 and +100.00.
- My recommendation for learning C programming: 'C Programming Absolute Beginner's Guide'
- Create your own scripts with GPC2 Scripting
User avatar
jelly44
Sergeant Major of the Army
Sergeant Major of the Army
 
Posts: 220
Joined: Tue Feb 05, 2019 3:49 pm

Previous

Return to GPC2 Script Programming

Who is online

Users browsing this forum: No registered users and 193 guests