Scripting / Coding Question
15 posts
• Page 2 of 2 • 1, 2
Re: Scripting / Coding Question
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
- Create your own scripts with GPC2 Scripting
-
jelly44 - Sergeant Major of the Army
- Posts: 220
- Joined: Tue Feb 05, 2019 3:49 pm
Re: Scripting / Coding Question
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!
Scripting, a game in the game.
Believe or dare, It's Titanic!
-
Prototype - Major General
- Posts: 3252
- Joined: Sun Dec 16, 2012 1:43 pm
Re: Scripting / Coding Question
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
- Create your own scripts with GPC2 Scripting
-
jelly44 - Sergeant Major of the Army
- Posts: 220
- Joined: Tue Feb 05, 2019 3:49 pm
Re: Scripting / Coding Question
Yes. Something like this:
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.
- 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.
-
Scachi - Brigadier General
- Posts: 3044
- Joined: Wed May 11, 2016 6:25 am
- Location: Germany
Re: Scripting / Coding Question
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
- Create your own scripts with GPC2 Scripting
-
jelly44 - Sergeant Major of the Army
- Posts: 220
- Joined: Tue Feb 05, 2019 3:49 pm
15 posts
• Page 2 of 2 • 1, 2
Return to GPC2 Script Programming
Who is online
Users browsing this forum: No registered users and 233 guests