Log In  

Hello.

I'm working on a batch utility to merge 7-Zip with Pico-8 and to work with directories outside Pico-8 as I have a need for this, yet I am running into a curious problem.

When I retrieve the directory, I am getting a filename back like:

3-d dOCKING mISSION (1978)(pROGRAMMA iNTERNATIONAL).DSK

@zep, could you please add some options to P8SCII such that I could convert this string line to 4-unique formats:

ORIGINAL:3-d dOCKING mISSION (1978)(pROGRAMMA iNTERNATIONAL).DSK
INVERSE :3-D Docking Mission (1978)(Programma International).dsk
LOWER   :3-d docking mission (1978)(programma international).dsk
UPPER   :3-D DOCKING MISSION (1978)(PROGRAMMA INTERNATIONAL).DSK
FIRSTCAP:3-D Docking Mission (1978)(Programma International).Dsk

It could be done via: "\c" followed by O I L U or F

It would then change the visual case for every character for that single PRINT or string definition line. Once a new string or definition is in place, the effect would not be there.

During the same text line you can use "\co" to turn it off and it is off by default.

Of course actually DOING caps to strings would be nice too with a new function called caps().

str=caps(str,1)
0 = No change
1 = Inverse
2 = Lower
3 = Upper
4 = Firstcap

P#120290 2022-11-07 23:23 ( Edited 2022-11-08 00:28)

1

Here is a caps function that should do as you specify

function caps(s,f)
 r = ""
 for i=1,#s do
  n=ord(s[i])
  o=n
  if ((f == 1 or f == 3 or (f==4 and (i == 1 or s[i-1] == " "))) and n >= 65 and n <= 90) o += 32
  if ((f == 1 or f == 2 or (f==4 and i != 1 and s[i-1] != " ")) and n >= 97 and n <= 122) o -= 32
  r ..= chr(o)
 end
 return r
end
P#120473 2022-11-11 06:03

That is some magnificent code, @mattu82 ! Well done.

The Caps to me though means any character that is NOT A-Z or a-z means the next will be uppercase, so if you had something like this:

he came in 1st place

That would become:

He Came In 1St Place

P#120487 2022-11-11 17:42

Let me try ...

function caps(t)
local u,r,c=1,""
  for i=1,#t do
    c=t[i]
    if u==0 and c>="a" and c<="z" then
      c=chr(ord(c)-32)
    end
    if c<"a" then
      u=1
    else
      u=0
    end
    if u==1 and c>="a" and c<="z" then
      c=chr(ord(c)+32)
    end
    r=r..c
  end
  return r
end

cls()
?caps("he came in 1st place.")

That gets me the results I want but certainly not as compact and smart as your code.

P#120488 2022-11-11 18:14 ( Edited 2022-11-11 18:18)

I had it so that it option 4 capitalized just after spaces. This should do it so it's after non-alphabetic.

function caps(s,f)
 r = ""
 flag = true
 for i=1,#s do
  n=ord(s[i])
  o=n
  if ((f == 1 or f == 3 or (f==4 and flag)) and n >= 65 and n <= 90) o += 32
  if ((f == 1 or f == 2 or (f==4 and not flag)) and n >= 97 and n <= 122) o -= 32
  r ..= chr(o)
  flag = (n < 65 or n > 90) and (n < 97 or n > 122) 
 end
 return r
end
P#120498 2022-11-11 19:56

Hi @mattu82:

You nailed it ! That's it. That is some lovely code.

Now if ZEP would just implement it all internally. :)

Actually someone made a request earlier to be able to create DLLs in Pico-8. That might be a good thing and we could stop hounding ZEP for new commands.

Then we could bundle up all kindsa functions together written by everyone and stuff 'em in a DLL.

Like your Caps() function for instance.

In the code it would be:

  uses("mattu82lib")
  cls()
  ?caps("uppercase",3)

You could even have a command called, useshelp(filename.dll) which would immediately call the function from that DLL called, instrux() or something and the author can give information about the DLL, who wrote it, how to use it, and what commands are all available for it. Possibly using the "breadcrumb" method.

For your code for instance it would be: useshelp("mattu82","caps") which would bring up topic specific help on your function caps() inside the DLL as you write and describe it, much like HELP and CTRL+U is being used today.

P#120500 2022-11-11 20:33
1

#include kind of does that. What might be helpful is if we could include files from splore, or maybe some offshoot of splore for data files. Then we could have something like #include #mattu82lib and have the compiler get the latest version of mattu82lib.p8 from splore.

For help, we could have a convention like if I put comments above a function:

--my function
--takes these arguments
--and does cool things
function myfunc(a,b)
...

Then that is what is returned from help

> help myfunc
my function
takes these arguments
and does cool things
P#120509 2022-11-11 21:45 ( Edited 2022-11-11 21:45)
1

Hi @mattu82:

#include does include, but I think what people want is a certain degree of protection to their code. That I believe was the driving force beyond DLLs.

Now when I wrote S2 years ago, a RPG Maker, as Worldbuilders (is what I called them) started to busily make their worlds and games in it, the age old question was brought up.

"How do I protect my work ?"

And at the time, I didn't have anything. I really wasn't expecting anyone TO protect their work. To just have it out in the open where everyone and everyone else could see how it was made. Play their world RPG, enjoy it and - to learn from it.

I'm pretty sure that's the vision ZEP has in mind with Pico-8.

The biggest problem I see with DLLs is just that. People can write some very high-order DLLs in Pico-8 that no-one can see the source-code to, and then maybe even start to charge money for them.

Then you have one-upmanship where one person tries to write the "end all" DLLs and arguments break out on whose is better. It happened in QBasic, Delphi, Bagel, and Blitz.

Perhaps I should take back my saying I would like a DLL ability. However, the concept of #include is pretty neat, especially if it could be read remote as you are saying, that would indeed open up some interesting possibilities.

#include #bigbossfunctions

The # in front of the filename to let you know it is on the internet.

It would also need the ability to be loaded via "#" as carts are today so someone can see the magic behind the spell - and no-one can accuse someone of writing a dangerous or irresponsible #include file as the source would always be open and available to examine.

I would hate to see Pico-8 go the route of protected, encrypted, and ultimately for-sale DLLs as so many other programming languages have before it.

So I agree and definitely 2nd the motion, allow #include to include online P8 files and libs.

P#120510 2022-11-11 22:04

[Please log in to post a comment]