Jump to content

ACTION_READLN - replacement examples


AL|EN

Recommended Posts

I suppose you could make the installer automatically increment a wrong letter by one until it hits a free slot. But yes, it's not not exactly user friendly.

 

Or else just define some defaults, and revert to the defaults unless the player choices pass validation.

Thank you both.

 

But my concern is both doesnt give the users a second chance if any defination goes wrong or they just forget it. It could become a mess when using an install tool if there are mods install after it.

Link to comment

Code that to 3 variables and well see on going with that...

I don't understand what this means.

It's fine, I don't either :)

Nice.

@DavidW

K. You propose a principle solution, without any details. I would like a weidu.tp2 code solution for this kind of problem, aka if you have a working .tp2 code example, show it to us.

Why I ask... cause I could use it in my mod. More on why I ask a .tp2 code, is that I could assume that you don't mean a .tp2 solution, but a install tool solution which is not what is asked in the original post, as he already has this in BWS that requires updates to every mod and so forth... which he doesn't want to support any more.

 

Link to comment

More on why I ask a .tp2 code, is that I could assume that you don't mean a .tp2 solution, but a install tool solution which is not what is asked in the original post

It's just computation and variable substitution; of course it can be done in tp2. Here's a quick version (perhaps there are more elegant ones):

 

// Checks if each of key_1, key_2, key_3 is a letter; replaces it with default value if not; uppercases it in any case.
// Then if any two of key_i, key_j are equal, replaces all three with default values
DEFINE_ACTION_FUNCTION verify_hotkeys
   STR_VAR key_1=""
           key_2=""
           key_3=""
           default_1="A"
           default_2="B"
           default_3="C"
   RET     key_1
           key_2
           key_3
BEGIN
      OUTER_FOR (i=1;i<=3;i+=1) BEGIN
         OUTER_SPRINT letter $key("%i%")
         LAF is_a_letter STR_VAR letter RET value END
         ACTION_IF !value BEGIN
            OUTER_SPRINT letter $default("%i%")
         END
         ACTION_TO_UPPER letter
         OUTER_SPRINT $key("%i%") "%letter%"
      END
      ACTION_IF ("%key_1%" STRING_EQUAL "%key_2%") || ("%key_1%" STRING_EQUAL "%key_3%") || ("%key_2%" STRING_EQUAL "%key_3%") BEGIN
         OUTER_FOR (i=1;i<=3;i+=1) BEGIN
             OUTER_SPRINT $key("%i%") $default("%i%")
         END
      END
END



/// Returns true iff input is A-Z or a-z
DEFINE_ACTION_FUNCTION is_a_letter
   STR_VAR letter=""
   RET value
BEGIN
   ACTION_IF !(STRING_LENGTH "%letter%"=1) BEGIN
      OUTER_SET value=0
   END ELSE BEGIN
      ACTION_IF "%letter%" STRING_MATCHES_REGEXP "[A-Za-z]" BEGIN
         OUTER_SET value=0
      END ELSE BEGIN
         OUTER_SET value=1
      END
   END
END
Edited by DavidW
Link to comment

...

Congratulation on input variable validation and substitution of a single character to three variables. But now you need to also take input from the installer, as you have not done so thus far. Aka you made a useful function, but you are not using it yet.

And can weidu use a function that has not been define-d before using it ? It is likely that, I read that from somewhere, but I just want to make sure.

And yeah, it might be a single line... or few in use-case depending things, but that counts.

 

What I intent to use is a mix of a .tpa coding, ALIENQuake's suggestion on default file and non-default file substitution to switch between the .tpa files, and functions that use their unique variable names on each component... and if the non-default inputs fail if its in the game folder, so what ... it will interrupt the install, as the mod user needs to re-edit that file or remove it to get the default file to usage. And a separated components to use insert the READNL variables during install that has variable verification for each.

This idea is still in the air, cause I haven't had the time and inclination to tackle (a lot of cursing)/it.

Edited by Jarno Mikkola
Link to comment

 

...

Congratulation on input variable validation and substitution of a single character to three variables. But now you need to also take input from the installer, as you have not done so thus far. Aka you made a useful function, but you are not using it yet.

Sorry, that’s the most of other people’s coding I’m willing to do right now!

Link to comment

 

...

Congratulation on input variable validation and substitution of a single character to three variables. But now you need to also take input from the installer, as you have not done so thus far. Aka you made a useful function, but you are not using it yet.

And can weidu use a function that has not been define-d before using it ? It is likely that, I read that from somewhere, but I just want to make sure.

And yeah, it might be a single line... or few in use-case depending things, but that counts.

 

What I intent to use is a mix of a .tpa coding, ALIENQuake's suggestion on default file and non-default file substitution to switch between the .tpa files, and functions that use their unique variable names on each component... and if the non-default inputs fail if its in the game folder, so what ... it will interrupt the install, as the mod user needs to re-edit that file or remove it to get the default file to usage. And a separated components to use insert the READNL variables during install that has variable verification for each.

This idea is still in the air, cause I haven't had the time and inclination to tackle (a lot of cursing)/it.

 

Tweaks pretty much has a working example of this. It will accept input from a config file, but if it contains invalid input then it falls back to ACTION_READLN. Granted the input is simpler, but it's had a working config/input scheme with validation since v1.

Link to comment

And can weidu use a function that has not been define-d before using it ?

I hadn't originally understood what you meant here. But: WEIDU can't actually use a function before it's defined. But you can include a function in part of the definition of another function before defining it (as I did above). WEIDU isn't strongly typed and doesn't do any kind of validation on variables when you define things; if you do LAF my_function END the install will fail if my_function isn't defined, but the failure happens at install time. You can put that line in a function or macro before you define my_function, provided that you define it before actually running that function or macro.

Link to comment

@DavidW, no need to be sorry... and I am glad of the help you, and other give.

Ahh, that's what I read in the ..somewhere. Thanks for the clarification.

Tweaks pretty much has a working example of this. It will accept input from a config file, but if it contains invalid input then it falls back to ACTION_READLN. Granted the input is simpler, but it's had a working config/input scheme with validation since v1.

You probably mean this in ALWAYS:

  ACTION_IF NOT VARIABLE_IS_SET cd_always THEN BEGIN
    OUTER_SET cd_always = 1 // just do this once per install
    ACTION_IF FILE_EXISTS ~cdtweaks/cdtweaks.txt~ THEN BEGIN
      INCLUDE ~cdtweaks/cdtweaks.txt~ // config file
	  ACTION_IF !VARIABLE_IS_SET romance_speed_use_config_values THEN BEGIN OUTER_SET romance_speed_use_config_values = 0 END
	  ACTION_IF !VARIABLE_IS_SET minimum_stats_use_config_values THEN BEGIN OUTER_SET minimum_stats_use_config_values = 0 END
	  ACTION_IF !VARIABLE_IS_SET romance_use_config_values       THEN BEGIN OUTER_SET romance_use_config_values = 0 END
    END ELSE BEGIN    
      OUTER_SET romance_speed_use_config_values = 0
      OUTER_SET minimum_stats_use_config_values = 0
      OUTER_SET romance_use_config_values = 0
    END

Yeah, ... that's like the idea... but I will probably have say 17 integers, a few Y/N -questions and their explanations in // -lines. And definitely non-zero defaults.

Hmm, that doesn't have the ... ACTION_READLN to fall back on to, and the whole folder doesn't contain the term either... unless my Windows can't read it for --- reasons.

Is there a file extension restriction on what the weidu can read via INCLUDE .. as a coding file. I know not to probably make a .wav file for reasons that should be obvious... but other-vice ?

Edited by Jarno Mikkola
Link to comment

 

Here's a quick version (perhaps there are more elegant ones):

Impresive! Thanks DavidW.

And I think an extra component with READLN to reconfigure the hotkeys (and modify the scripts) could fix the typo/conflict issue.

 

And, if I may, that function can be further shortened. You can dump the string length check and just use a regexp match against ~^[A-Za-z]$~, as it would only match a one-character input.

Link to comment

 

 

Here's a quick version (perhaps there are more elegant ones):

Impresive! Thanks DavidW.

And I think an extra component with READLN to reconfigure the hotkeys (and modify the scripts) could fix the typo/conflict issue.

 

And, if I may, that function can be further shortened. You can dump the string length check and just use a regexp match against ~^[A-Za-z]$~, as it would only match a one-character input.

 

Ahh...You just opened a new door to me. Thanks very much.
Link to comment

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...