StrCreate.gph : Adds some functions for dyn. string creation

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

StrCreate.gph : Adds some functions for dyn. string creation

Postby Scachi » Tue Dec 18, 2018 8:50 am

This header file adds some functions to help with dynamic string creation.

Usage:
Download the headerfile "StrCreate.gph" or example script "StrCreate_Examples" from the Online Resource.

Place this file into the same directory where your script file is.
Add this line to your script:
Code: Select all
#include "StrCreate.gph"


It provides the functions:
  • StrCreate (char *src1, uint32 num, char *src2, char *dst, uint8 digits, char fill)
    Example function to create a string by merging char*,num,char*
    If you want to create another filename pattern you can disable this function by adding this line above the include line:
    Code: Select all
    #define STRCREATE_OWN
  • StrAddTxt (uint8 index, char *src, char *dst)
    Starting at array[index], add the char*
  • StrAddChr (uint8 index, char src, char *dst)
    Insert at array[index], single char
  • StrAddInt (uint8 index, uint32 Num, char *dst, uint8 digits, char fill)
    Starting at array[index], add the number uint32 with optional minimum number of digits and char to use for missing digits

By default the functions are inserting '\0' after addition of a segment to end the string.
If you want to be able to change any index without having to rebuild the whole string each time you have to add this line above the include line:
Code: Select all
#define STRCREATE_INSERT

You will have to track the end index of your string yourself and end it with the function:
Code: Select all
StrEnd(indexEnd,char *dst);


----------
Example code to start recording a macro , creating a filename by number of recordings done.
Press BUTTON_16 to increase the counter start recording.
Code: Select all
 
#include "StrCreate.gph"
 
uint32 num = 0;
char MacName[12];
 
main {
 
  // press BUTTON_16 (PS4:Cross,XB:A) to increase the counter and start recording
  if (event_active(BUTTON_16) && macro_time() == -1) {
    num++;
    num=clamp(num,0,999999);
    StrCreate("m_",num,".gmk",&MacName,6,'0');
    printf("Start recording macro. Filename:");
    printf(&MacName);
    macro_rec(&MacName);
  }
 
  // stop recording of the macro after 5 seconds
  if ( macro_time() >= 5000 ) {
    macro_stop();
    printf("Stopped recording. Filename:");
    printf(&MacName);
  }
}
 

Output Panel:
Code: Select all
GVM Output: Start recording macro. Filename:
GVM Output: m_000001.gmk
GVM Output: Stopped recording. Filename:
GVM Output: m_000001.gmk
GVM Output: Start recording macro. Filename:
GVM Output: m_000002.gmk
GVM Output: Stopped recording. Filename:
GVM Output: m_000002.gmk


----------
Example creating a custom pattern 'm',00-99,'_',0000-9999,".gmk"
Press DPad_Up to increase 00-99, DPad_Down to increase 0000-9999 segment
Code: Select all
 
#define STRCREATE_OWN
#include "StrCreate.gph"
 
uint32 num1 = 1;
uint32 num2 = 10;
 
char MacName[12];
 
main {
 
  // press BUTTON_10 to increase num1
  if (event_active(BUTTON_10)) {
    num1++;
    num1=clamp(num1,0,99);
    StrCreate('m',num1,'_',num2,".gmk",&MacName);
    printf("Name:");
    printf(&MacName);
 
  }
 
  // press BUTTON_11 to increase num2
  if (event_active(BUTTON_11)) {
    num2++;
    num2=clamp(num2,0,9999);
    StrCreate('m',num1,'_',num2,".gmk",&MacName);
    printf("Name:");
    printf(&MacName);
 
  }
 
}
 
 
void StrCreate(char src1,uint32 num1, char src2, uint32 num2,char *src3,char *dst) {
  uint8 i=0;
 
  i=StrAddChr(i,src1,dst);
  i=StrAddInt(i,num1,dst,2);
  i=StrAddChr(i,src2,dst);
  i=StrAddInt(i,num2,dst,4);
  i=StrAddTxt(i,src3,dst);
}
 

Output Panel:
Code: Select all
GVM Output: Name:
GVM Output: m02_0010.gmk
GVM Output: Name:
GVM Output: m03_0010.gmk
GVM Output: Name:
GVM Output: m03_0011.gmk
GVM Output: Name:
GVM Output: m03_0012.gmk


For more examples download "StrCreate_Examples" from the Online Resource.
User avatar
Scachi
Brigadier General
Brigadier General
 
Posts: 3044
Joined: Wed May 11, 2016 6:25 am
Location: Germany

Return to User's Script Documentation

Who is online

Users browsing this forum: No registered users and 121 guests