arguments for commands

Ask and answer questions about making games and related topics. Unrelated topics go in that other forum.

Moderators: marionline, SDHawk

Post Reply
User avatar
SwordPlay
Chemical Slime
Posts: 966
Joined: Sun Jan 22, 2017 9:32 am
Location: London, England
Contact:

arguments for commands

Post by SwordPlay »

I want to use this command:

- slice at pixel (parent, x, y, number, check descendants, visible only)

but I don't want to use the arguments "number" or "check descendants"
How should this be formatted?
User avatar
Newbie Newtype
Reigning Smash Champion
Posts: 1873
Joined: Mon Oct 15, 2007 9:44 pm

Post by Newbie Newtype »

Pass 0 for number and true for check descendants (these are the default values). I believe you can just leave them blank too as long as the gaps are separated by commas, but I could be wrong.
<TheGiz> oh hai doggy, oh no that's the straw that broke tjhe came baclsb
User avatar
SwordPlay
Chemical Slime
Posts: 966
Joined: Sun Jan 22, 2017 9:32 am
Location: London, England
Contact:

Post by SwordPlay »

Thanks for that
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

You can't skip an argument by putting leaving it out (although that's something I want to implement). HSpeak will interpret two commas next to each other as a single comma! I've just patched HSpeak to disallow it.

So you have to give the default values to skip an argument. The plotdict should tell you what the defaults are, but you can also look in plotscr.hsd.
User avatar
Bob the Hamster
Lord of the Slimes
Posts: 7660
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

Yeah, the double-comma collapse thing is an artefact if me being very lazy with parsing 18 or so years ago.

Happy to see it change. I wonder if any existing scripts at all actually use ,, anywhere? I am guessing probably not
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

I wonder if any existing scripts at all actually use ,, anywhere? I am guessing probably not
I'm sure I've seen it, along with abuses of most of the other things HSpeak allows but shouldn't!
I sure is nice that we don't have to maintain strict source-level compatibility.
(I still haven't given up on the idea of adding - for subtract, somehow!)
Last edited by TMC on Wed May 17, 2017 5:12 pm, edited 1 time in total.
User avatar
Bob the Hamster
Lord of the Slimes
Posts: 7660
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

TMC wrote:(I still haven't given up on the idea of adding - for subtract, somehow!)
What about a per-source-file top-level pragma like:

Code: Select all

allow troublesome dashes
Which would turn on a backcompat mode for people who want to be able to recompile their scripts without having to fix all of their existing -- operators.

That solution has some downsides, but I'm just thinking out loud here :)

We could even check if the input .hss file has a modification time older than the switch to - as the default subtraction operator, and output an appropriate warning message

I think that we would also want subtracting a negative number to always have a mandatory space between the two - symbols.

... actually, in this scenario, couldn't -- always produce an error/warning when "allow troublesome dashes" is not enabled? I don't feel a need to ever support C++ style decrement operator when we already have a perfectly good n -= 1
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

Yes, I like the idea of requiring subtract negative to be written with a space between the two -'s, and doing a search-and-replace is easy even in Notepad.
(Also currently we support spaces in the middle of a two-character operator, like + = but I see no good reason for that.)
So switching from -- to - would not really be that big a deal since HSpeak would just tell you to either search-and-replace if it saw a -- ... were it not for a far more serious problem, which is that - is currently allowed in identifiers!

I used rpgbatch to scan zip files for included scripts and extracted them (download here). There were 243 .zips with scripts. I didn't extract anything out of .rpg files, but I'll try that in future; this sample is still only small and published scripts will generally be better written.

I searched for scripts using - in identifiers (regex "^[^\"#]*\([^\"#-] *- *[^-=0-9]\|\w *- *[^-=]\)") and found it's actually pretty common. Even Wandering Hamster does it (Fluffy-Mu)! Out of 243 there were 27 games which did so:

Code: Select all

./cp-20/wander.hss
./cp-213/JUNKBOB.HSS
./cp-295/new-wanderp.hss
./cp-433/steve.txt
./cp-601/chat.hss
./cp-601/test.hss
./cp-601/text.hss
./cp-634/RPG File-DESTINY.HSS
./cp-666/Breath of Fire Script.hss
./cp-757/The Ritual-scripts-ritual.hss
./cp-951/1day irc.hss
./extra-COFFEE1--playtest/COFFEE1.txt
./extra-POWERXE--playtest/POWERXE.txt
./opohr-Metamorphosis/528MORPH.HSS
./ss-3dmaze_187/3dmaze-scriptmockup.txt
./ss-3dmazebase_205/3dmazebase-scriptmockup.txt
./ss-amped_220/Amped.hss
./ss-automagically_bizzaro_carnival_in_salad_kingdom_648/12345automagically.txt
./ss-festivus_192/festivus-scriptmockup.txt
./ss-first_fantasy_161/FF_Scripts.txt
./ss-hero_680/Hero-Hero.HS.txt
./ss-lilith_688/battle.hss
./ss-monstergame_techdemo_116/scripts-8bit.txt
./ss-noes_163/NOES-NOES.txt
./ss-ravu_171/Love.hss
./ss-seasons_demo_188/Seasons_Demo-Seasons_Demo-JaneRed_Script_both.HSS
./ss-star_wohrs_123/Star wOHRs.txt
./ss-testone_174/111.hss
./ss-thesuperamazingblueballgame_821/rewrite.hss
./ss-z_level_960/Scripts-main.hss
Quite a few of them are from sidescroller 101 games, eg hero-vx.
So either we would need a compiler directive to choose whether - is an operator instead of a valid identifier (which would need to be per-file so that plotscr.hsd can go one way, which would mean not being able to call scripts containing - in the name from a file using - as an operator), or we need to forget the idea.

I also checked how many people use - with a space on either the left or right side, and aside from a bunch of negative numbers written with a space, like - 30, these were the only occurrences:

Code: Select all

./ss-z_level_960/Scripts-main.hss&#58;plotscript, Map 01 - Middle, begin
./ss-z_level_960/Scripts-main.hss&#58;plotscript, Map 02 - Top, begin
./ss-z_level_960/Scripts-main.hss&#58;plotscript, Map 03 - Bottom, begin
I searched for scripts containing a space in the middle of an operator ("^[^\"#]*[-+<>.^|&:/] \+[+<>.^|&:/]" and a separate search for "- \+-") and there were none. I'm pleased to delete that block of code!

I checked for scripts containing two commas next to each other and there were only two.
Last edited by TMC on Thu May 18, 2017 10:12 am, edited 3 times in total.
User avatar
Bob the Hamster
Lord of the Slimes
Posts: 7660
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

Yes, the thing about dashes being allowed in script and variable names was the main thing I was thinking of for the "allow troublesome dashes" directive.

Getting rid of -- in my own scripts would feel pretty nice :)
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

It would be like two different language versions, with HSpeak supporting both.

Since you have to declare a variable or script to use it, and 'subtract' isn't allowed inside variable/globalvariable/an arglist, HSpeak would easily detect when you need to add the directive to your scripts.

Making the directive act only on the current file (well actually, only the part of the file below the directive) makes it easy to mix different language versions in the same game if using scripts from elsewhere. There could be an inverse/undo directive to make it even easier.

So, this all sounds perfect.

-- is annoying, but the other thing that's worse is 'return'. Changing the meaning of return would be confusing. I feel "exit returning" is too long though. "return!" or "return now" or "do return" as an alternative? (Hmm... if we had macros...)
(Taking the same no-surprises approach to 'return' as to '--' would be to remove 'return' except when a directive is used, and otherwise replace it with 'setreturn' and 'doreturn'.)
Last edited by TMC on Thu May 18, 2017 2:32 pm, edited 1 time in total.
User avatar
Bob the Hamster
Lord of the Slimes
Posts: 7660
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

I can live with "return" being weird, and "exit returning" being long. Those only bother me about 1/10th as much as -- ever did ;)

"return!" is amusing and appealing.

"do return" and "return now" are also perfectly reasonable.
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

"return now" is only 4 characters shorter than "exit returning". "do return" on the other hand...
! might yet prove to be useful for some other syntactical purpose.

How about "exit". It's short for both "exit script" and "exit returning", and it can be a replacement for both: either give it an argument, or don't, in which case the last "return" is used.
Edit: zero occurrences of "exit" in those 243 games.
Last edited by TMC on Thu May 18, 2017 5:56 pm, edited 1 time in total.
User avatar
Bob the Hamster
Lord of the Slimes
Posts: 7660
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

Beautiful! "exit" sounds perfect.
User avatar
kylekrack
Liquid Metal Slime
Posts: 1242
Joined: Mon Jun 16, 2014 8:58 am
Location: USA
Contact:

Post by kylekrack »

I agree that 'return' and 'exit returning' aren't very bothersome. At least the difference between them is pretty self-evident, and 'exit returning' being long hasn't ever bothered me. However, 'exit' sounds great. Way cleaner than using those two commands independently.
My pronouns are they/them
Ps. I love my wife
Post Reply