[Header] SafePrint

Documentation, usage tips and configuration guides for Titan Two scripts and bytecodes published by the community users.

[Header] SafePrint

Postby PoshLemur » Sat May 05, 2018 8:39 am

Available now on Gtuner's Online Resources / GPC Headers!

This script will prevent printf from crashing Gtuner by limiting the frequency at which it can print.
It's verbose, so you'll know when and how many printf calls were suppressed.

Default printf limit is capped at 20 messages every 600ms. However this can easily be decreased or increased to fit your needs by editing the header file.

UPDATE: Now allows for printf to be run in bursts, with a cool down after the burst threshold has been past. This allows for multiple printf calls on the same loop without them being suppressed.

Usage:
Code: Select all
 
#include "safeprint.gph" // Requires header file to be inside same directory as your script.
 
init {
    _printf("Warning!"); // This line will crash Gtuner if in a loop because it calls printf directly.
}
 
main {
    printf("Hello ConsoleTuner!"); // Safe to use inside the main loop!
}
 


Changelog:
Code: Select all
 
Update 1.35:
 Fixed a problem with the warning message showing the incorrect number of suppressions.
 Fixed a problem where printf would have cause problems in if ... else statements without braces,
 by wrapping the statement inside a do while loop.
 
Last edited by PoshLemur on Sun May 06, 2018 9:11 pm, edited 4 times in total.
My github account: [link]
User avatar
PoshLemur
Sergeant Major
Sergeant Major
 
Posts: 75
Joined: Thu Mar 08, 2018 9:26 am

Re: [Header] SafePrint

Postby bonefisher » Sat May 05, 2018 1:39 pm

:smile0517:
bonefisher
Lieutenant General
Lieutenant General
 
Posts: 5413
Joined: Thu Jan 29, 2015 10:49 am

Re: [Header] SafePrint

Postby Sillyasskid » Sun May 06, 2018 4:20 pm

I see....

I actually made a similar header file like this, months back.
friendlyprintf.gph

Your header seems to differ a lot from mine, My header was written to purposely to unload the script,before a number of print falls are made. but I can see in your header. This is only half the case, your solution. seems
to be keep the script running, while suppressing the actual printf() calls. I'm curious why you chose to have your header handle the script in this ways, Rather than simply unloading the script when you notice too many printf calls. ?

Code: Select all
#include <safeprint.gph> // use this only if the gph file is inside the located inside the include folder
//#include "safeprint.gph" // use this ift the .gph file is in the same folder as the gpc file.
 
    init {
        if (printf("Hello world!")) {
 
        }   
}


I also wanted to share something I found with your header, Because you did not format your macro like function correctly, You Can no longer use printf as a parameter in any function. The above example wont work because your using { } to format the actual macro like function. And these { } brackets cant go inside normal ( ) brackets, You need to reformat the macro If you want it to work like normal
User avatar
Sillyasskid
Captain
Captain
 
Posts: 574
Joined: Sat May 14, 2016 3:07 am

Re: [Header] SafePrint

Postby PoshLemur » Sun May 06, 2018 5:03 pm

Hi Silly,
Thank you I'll look into it, but why would you try using a printf as a conditional when it returns void according to the T2 documentation? In C it returns the number of character printed, but not here.

I tried friendlyprintf, it works very well for what it does!! The problem was for me that friendlyprintf just didn't work how I wanted it to work, other than that it worked perfectly as intended! :) Safeprint just tries to handle the problem differently.

For me personally, I want the script to continue running so that if there is a problem in a combo loop or a specially triggered loop that hasn't been fully tested. It won't unload the script altogether while I'm play testing it. I'll be able to go back in and see "hey! there are a lot of "WARNING: 70 printf() call(s) suppressed since last printf." messages and fix the problem after my play session.
My github account: [link]
User avatar
PoshLemur
Sergeant Major
Sergeant Major
 
Posts: 75
Joined: Thu Mar 08, 2018 9:26 am


Return to User's Script Documentation

Who is online

Users browsing this forum: No registered users and 137 guests