JASS can't do that -or- The quine challenge

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
> At least you can delete that part of my post so I don't look like a fool

You sure that would help?



FWIW, here's a version using a "globals" block:
JASS:
globals
string s="globals
string s=\"\\
endglobals
function F takes nothing returns nothing
call DisplayTextToPlayer(GetLocalPlayer(),0,0,SubString(s,0,18) + SubString(s,0,17) + SubString(s,18,19) + SubString(s,17,19) + SubString(s,18,999) + SubString(s,17,18) + SubString(s,19,999))
endfunction"
endglobals
function F takes nothing returns nothing
call DisplayTextToPlayer(GetLocalPlayer(),0,0,SubString(s,0,18) + SubString(s,0,17) + SubString(s,18,19) + SubString(s,17,19) + SubString(s,18,999) + SubString(s,17,18) + SubString(s,19,999))
endfunction


Clearly inferior to the all-in-one version.



> I fail to see how Ace code works

That's because it's Ace code... :p

The reason why the approach in post #4 can't work is because it ignored the following basic fact:
You need the code as data, and show it once as code and once inside itself.
Basically, a recursive display that reconstructs both the code (function) and the data (string) from just the data.

An additional difficulty is using " inside a string, and, worse, using \ inside a string.
Both need escaping.
And, well, when displaying that, it needs even more escaping...

Hence the abuse on substrings.

Still, with a bit of sitting down and thinking it through (i.e. start counting characters)...


" Never let the one that says it can't be done interrupt the one who's doing it. "
 

UndeadDragon

Super Moderator
Reaction score
447
I don't particularly use JASS, but what's with all the substrings? What about setting the text in an array and looping through it, like:

JASS:
function F takes nothing returns nothing
    local string array text
    local integer i = 0
    set text[0]="function F takes nothing returns nothing"
    set text[1]="     call DisplayTimedTextToPlayer(Player(0),0,0,10.00,\"text\")"
    set text[2]="endfunction"
    loop
        exitwhen i == 3
        call DisplayTimedTextToPlayer(Player(0),0,0,10.00,text<i>)
        set i=i+1
    endloop
endfunction</i>
 

duyen

New Member
Reaction score
214
As AceHart said this is impossible, and no the function technically does not echo it's source due to the fact that it would be endless.
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
> What about setting the text in an array and looping through it

Whatever works.

Have a look at what you get on screen when you run your function.
Does it look like your function? Precisely and exactly, to the last character?
In short, "it needs work".


> ... post just above

Ehm... what?
 

UndeadDragon

Super Moderator
Reaction score
447
If I try to make it display the whole source code, it makes the code endless, I didn't realise :rolleyes:
 

tom_mai78101

The Helper Connoisseur / Ex-MineCraft Host
Staff member
Reaction score
1,706
The title is the result of some (nearly) random MSN "talk".

The idea was to write a JASS function that, when called, would display its own source code.

Obviously, this can not be done.
Hence the following function that does it anyway:
JASS:
function F takes nothing returns nothing
local string s1=&quot;function F takes nothing returns nothing
local string s1=&quot;
local string s2=&quot;local string s2=
call DisplayTextToPlayer(GetLocalPlayer(),0,0,s1 + s + s1 + s + SubString(s2,16,17) + SubString(s2,0,16) + s + SubString(s2,0,1000) + s + SubString(s2,16,17) + SubString(s2,0,14) + SubString(s2,15,16) + s + e + s + s + SubString(s2,16,17) + SubString(s2,0,13) + SubString(s1,14,15) + SubString(s2,15,16) + s + e + e + s + SubString(s2,16,17) + SubString(s2,17,1000))
endfunction&quot;
local string s=&quot;\&quot;&quot;
local string e=&quot;\\&quot;
call DisplayTextToPlayer(GetLocalPlayer(),0,0,s1 + s + s1 + s + SubString(s2,16,17) + SubString(s2,0,16) + s + SubString(s2,0,1000) + s + SubString(s2,16,17) + SubString(s2,0,14) + SubString(s2,15,16) + s + e + s + s + SubString(s2,16,17) + SubString(s2,0,13) + SubString(s1,14,15) + SubString(s2,15,16) + s + e + e + s + SubString(s2,16,17) + SubString(s2,17,1000))
endfunction


While the output on screen is somewhat prohibitive, "Message log" and a screenshot or two do, indeed, allow to verify that the function does display itself (including "s, \s and newlines).


In need of a challenge?
+20 rep. for a function that does the same, preferably shorter.
Aha! Acehart didn't mention that the code must be displayed just once! Oh yeah, found something good... So, UndeadDragon is legitimate. Although...when Acehart typed "it needs work", I thought that looping counts. And please, don't sneak up on me and whack my head. I've seen too many animes before...

EDIT: Weird...spoiler tags doesn't work correctly.
 

Flare

Stops copies me!
Reaction score
662
Aha! Acehart didn't mention that the code must be displayed just once! Oh yeah, found something good... So, UndeadDragon is legitimate. Although...when Acehart typed "it needs work", I thought that looping counts. And please, don't sneak up on me and whack my head. I've seen too many animes before...

EDIT: Weird...spoiler tags doesn't work correctly.
UndeadDragon's isn't everything it's only displaying
Code:
function F takes nothing returns nothing
  call DisplayTimedTextToPlayer (Player (0), 0, 0, 10.00, "text")
endfunction
But, there's variables (and a loop) in the function, and they aren't being displayed
 

tom_mai78101

The Helper Connoisseur / Ex-MineCraft Host
Staff member
Reaction score
1,706
Oh...

---

And about the spoilers tag, is there something wrong?
 

Romek

Super Moderator
Reaction score
964
> Then how come I can't hide the quote that contains your entire #1 post?
They've been redesigned so you can't nest them, and they don't hide stuff that doesn't need hiding. :)
 

quraji

zap
Reaction score
144
Just for anyone who wants a wack at this:

The point is to make a code that displays it's own source code. In other words, what is displayed in-game should look just the same as in the editor (as if you copy-pasted it).
 

Strilanc

Veteran Scripter
Reaction score
42
More lines, but a couple hundred characters shorter than the one in the first post, but definitely behind the later ones. Not to mention fewer magic numbers. If jass had a string replace function, it would be so much easier.

JASS:
globals
string s=&quot;globals
string s=
string q=\&quot;\\\&quot;\&quot;
string z=q
string c
integer i=0
function F takes nothing returns nothing
loop
exitwhen i&gt;=999
set c = SubString(s,i,i+1)
if c==\&quot;\\\\\&quot; or c==q then
set z=z+\&quot;\\\\\&quot;
endif
set z=z+c
set i=i+1
endloop
call BJDebugMsg(SubString(s,0,17)+z+q+SubString(s,17,999))
endfunction&quot;
string q=&quot;\&quot;&quot;
string z=q
string c
integer i=0
endglobals
function F takes nothing returns nothing
loop
exitwhen i&gt;=999
set c = SubString(s,i,i+1)
if c==&quot;\\&quot; or c==q then
set z=z+&quot;\\&quot;
endif
set z=z+c
set i=i+1
endloop
call BJDebugMsg(SubString(s,0,17)+z+q+SubString(s,17,999))
endfunction
 

Builder Bob

Live free or don't
Reaction score
249
Here's one using an array

JASS:
function F takes nothing returns nothing
local string array s
local integer i=0
set s<i>=&quot;function F takes nothing returns nothing
local string array s
local integer i=0
set s<i>=&quot;
set i=i+1
set s<i>=&quot;
set i=i+1
set s<i>=&quot;
set i=i+1
set s<i>=&quot;\&quot;&quot;
set i=i+1
set s<i>=&quot;\\&quot;
set i=i+1
set s<i>=&quot;
call DisplayTextToPlayer(GetLocalPlayer(),0,0,s[0]+s[2]+s[0]+s[2]+s[1]+s[2]+s[1]+s[2]+s[1]+s[2]+s[3]+s[2]+s[2]+s[1]+s[2]+s[3]+s[3]+s[2]+s[1]+s[2]+s[4]+s[2]+s[4])
endfunction&quot;
call DisplayTextToPlayer(GetLocalPlayer(),0,0,s[0]+s[2]+s[0]+s[2]+s[1]+s[2]+s[1]+s[2]+s[1]+s[2]+s[3]+s[2]+s[2]+s[1]+s[2]+s[3]+s[3]+s[2]+s[1]+s[2]+s[4]+s[2]+s[4])
endfunction</i></i></i></i></i></i></i>
 

Strilanc

Veteran Scripter
Reaction score
42
Here's one using an array

JASS:
function F takes nothing returns nothing
local string array s
local integer i=0
set s<i>=&quot;function F takes nothing returns nothing
local string array s
local integer i=0
set s<i>=&quot;
set i=i+1
set s<i>=&quot;
set i=i+1
set s<i>=&quot;
set i=i+1
set s<i>=&quot;\&quot;&quot;
set i=i+1
set s<i>=&quot;\\&quot;
set i=i+1
set s<i>=&quot;
call DisplayTextToPlayer(GetLocalPlayer(),0,0,s[0]+s[2]+s[0]+s[2]+s[1]+s[2]+s[1]+s[2]+s[1]+s[2]+s[3]+s[2]+s[2]+s[1]+s[2]+s[3]+s[3]+s[2]+s[1]+s[2]+s[4]+s[2]+s[4])
endfunction&quot;
call DisplayTextToPlayer(GetLocalPlayer(),0,0,s[0]+s[2]+s[0]+s[2]+s[1]+s[2]+s[1]+s[2]+s[1]+s[2]+s[3]+s[2]+s[2]+s[1]+s[2]+s[3]+s[3]+s[2]+s[1]+s[2]+s[4]+s[2]+s[4])
endfunction</i></i></i></i></i></i></i>


I see, you're using the common s to try to shorten it. I think the clunkyness of having to put [#] on everything is making it longer in the end, though.
 

Builder Bob

Live free or don't
Reaction score
249
I see, you're using the common s to try to shorten it. I think the clunkyness of having to put [#] on everything is making it longer in the end, though.


Probably, but it's the thought behind is that counts.

After looking at your function a few more times, I now see the logic behind it. It's really cool how you build your string like that.
 

SFilip

Gone but not forgotten
Reaction score
634
Here's my take. 4 SubString calls total.
JASS:
function F takes nothing returns nothing
local string c1=&quot;\&quot;&quot;
local string c2=&quot;\\&quot;
local string s1=&quot;function F takes nothing returns nothing
local string c1=&quot;
local string s2=&quot;
local string c2=&quot;
local string s3=&quot;
local string s1=
local string s2=
local string s3=
call DisplayTextToPlayer(GetLocalPlayer(),0,0.6,s1+c1+c2+c1+c1+s2+c1+c2+c2+c1+SubString(s3, 0, 18)+c1+s1+c1+SubString(s3, 18, 36)+c1+s2+c1+SubString(s3, 36, 54)+c1+s3+c1+SubString(s3, 54, 300))
endfunction&quot;
call DisplayTextToPlayer(GetLocalPlayer(),0,0.6,s1+c1+c2+c1+c1+s2+c1+c2+c2+c1+SubString(s3, 0, 18)+c1+s1+c1+SubString(s3, 18, 36)+c1+s2+c1+SubString(s3, 36, 54)+c1+s3+c1+SubString(s3, 54, 300))
endfunction
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top