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.
  • The Helper The Helper:
    What is up WildTurkey?
  • The Helper The Helper:
    Looks like Google fixed whatever mistake that made the recipes on the site go crazy and we are no longer trending towards a recipe site lol - I don't care though because it motivated me to spend alot of time on the site improving it and at least now the content people are looking at is not stupid and embarrassing like it was when I first got back into this like 5 years ago.
  • The Helper The Helper:
    Plus - I have a pretty bad ass recipe collection now! That section of the site is 10 thousand times better than it was before
  • The Helper The Helper:
    We now have a web designer at my job. A legit talented professional! I am going to get him to redesign the site theme. It is time.
  • Varine Varine:
    I got one more day of community service and then I'm free from this nonsense! I polished a cop car today for a funeral or something I guess
  • Varine Varine:
    They also were digging threw old shit at the sheriff's office and I tried to get them to give me the old electronic stuff, but they said no. They can't give it to people because they might use it to impersonate a cop or break into their network or some shit? idk but it was a shame to see them take a whole bunch of radios and shit to get shredded and landfilled
  • The Helper The Helper:
    whatever at least you are free
  • 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!

      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