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,694
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,694
Oh...

---

And about the spoilers tag, is there something wrong?
 

Romek

Super Moderator
Reaction score
963
> 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.

      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