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

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
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="function F takes nothing returns nothing
local string s1="
local string s2="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"
local string s="\""
local string e="\\"
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.
 

Darthfett

Aerospace/Cybersecurity Software Engineer
Reaction score
615
Well this doesn't really count, but "call BJDebugMsg(" is shorter than "call DisplayTextToPlayer(GetLocalPlayer(),0,0," is shorter (and less flexible :rolleyes:).

But here it is anyway :p

JASS:
function F takes nothing returns nothing
local string s1="function F takes nothing returns nothing
local string s1="
local string s2="local string s2=
call BJDebugMsg(s1 + s + s1 + s + SubString(s2,16,17) + SubString(s2,0,16) + s + SubString(s2,0,999) + 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,999))
endfunction"
local string s="\""
local string e="\\"
call BJDebugMsg(s1 + s + s1 + s + SubString(s2,16,17) + SubString(s2,0,16) + s + SubString(s2,0,999) + 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,999))
endfunction


I also used 999 instead of 1000 to make it a few characters shorter.

Cool idea. :p
 

Vestras

Retired
Reaction score
248
JASS:
function F takes nothing returns nothing
local string s1="function F takes nothing returns nothing
local string s1="
local string s2="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 + s + s + s + s + SubString(s2,16,17) + SubString(s2,0,13) + SubString(s1,14,15) + SubString(s2,15,16) + s + s + s + s + s + s + SubString(s2,16,17) + SubString(s2,17,1000))
endfunction"
local string s="\""
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 + s + s + s + s + SubString(s2,16,17) + SubString(s2,0,13) + SubString(s1,14,15) + SubString(s2,15,16) + s + s + s + s + s + s + SubString(s2,16,17) + SubString(s2,17,1000))
endfunction


One line shorter.
 

Sooda

Diversity enchants
Reaction score
318
Might be cheesy, but AceHart made his first string like that, displays source code of function:
JASS:
function F takes nothing returns nothing
    call DisplayTextToPlayer(GetLocalPlayer(),0,0, "function F takes nothing returns nothing
    call DisplayTextToPlayer(GetLocalPlayer(),0,0, \"\")
endfunction")
endfunction

EDIT:
It just seems wrong, I fail to see how Ace code works. My function source code is:
JASS:
function F takes nothing returns nothing
    call DisplayTextToPlayer(GetLocalPlayer(),0,0, "")
endfunction

I'm confused.
 

Builder Bob

Live free or don't
Reaction score
249
Slightly different, but much the same

JASS:
function F takes nothing returns nothing
local string s="function F takes nothing returns nothing
local string s=\"\\
call DisplayTextToPlayer(GetLocalPlayer(),0,0,SubString(s,0,56)+SubString(s,56,57)+SubString(s,0,56)+SubString(s,57,58)+SubString(s,56,57)+SubString(s,57,58)+SubString(s,57,58)+SubString(s,58,59)+SubString(s,59,347)+SubString(s,56,57)+SubString(s,58,59)+SubString(s,59,347))
endfunction"
call DisplayTextToPlayer(GetLocalPlayer(),0,0,SubString(s,0,56)+SubString(s,56,57)+SubString(s,0,56)+SubString(s,57,58)+SubString(s,56,57)+SubString(s,57,58)+SubString(s,57,58)+SubString(s,58,59)+SubString(s,59,347)+SubString(s,56,57)+SubString(s,58,59)+SubString(s,59,347))
endfunction
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
> One line shorter.

In case you missed it, the idea was for that "better" version to still work correctly.


> Might be cheesy

As long as it works...
Yours doesn't.


> Slightly different, but much the same

Clearly. But it's good nonetheless.
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
> No idea if it lets to declare the global string like that...

That's not strictly a function anymore...
And, either way, if it needs a global block, that block is part of the code and must be displayed as well. Currently, it doesn't.
 

tom_mai78101

The Helper Connoisseur / Ex-MineCraft Host
Staff member
Reaction score
1,704
Question:

Why can't we just use 1 function, and type the whole code in a string variable?

EDIT: I copy-pasted and tested the JASS code Acehart posted, and it failed to trigger in WC3.

EDIT2: Waaait a minute...
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
> it failed to trigger

It's not a trigger, just a function.

I used this to call it, automatically and on command if needed:
Trigger:
  • Call
    • Events
      • Time - Elapsed game time is 1.00 seconds
      • Player - Player 1 (Red) skips a cinematic sequence
    • Conditions
    • Actions
      • Custom script: call F()


With the function in the header.


> ... Bob's

You can cut down on the SubString calls:
JASS:
function F takes nothing returns nothing
local string s="function F takes nothing returns nothing
local string s=\"\\
call DisplayTextToPlayer(GetLocalPlayer(),0,0,SubString(s,0,56) + SubString(s,56,57) + SubString(s,0,56) + SubString(s,57,58) + SubString(s,56,57) + SubString(s,57,58) + SubString(s,57,58) + SubString(s,58,999) + SubString(s,56,57) + SubString(s,58,999))
endfunction"
call DisplayTextToPlayer(GetLocalPlayer(),0,0,SubString(s,0,56) + SubString(s,56,57) + SubString(s,0,56) + SubString(s,57,58) + SubString(s,56,57) + SubString(s,57,58) + SubString(s,57,58) + SubString(s,58,999) + SubString(s,56,57) + SubString(s,58,999))
endfunction


Still the best so far... :p
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
Reason? Good? What?

- Fun?
- Because you can?
- Keep people busy?
- Learn something new today?
- Because there's always a better way to do it?
- Because!
 

Builder Bob

Live free or don't
Reaction score
249
Doing things purely with the reason that we can, is always fun.

I would like to ask a little question. When you say "preferably shorter", do you mean shorter in lines of code, characters used, processing power required/function calls used, amount of text printed in-game, something different, or a combination of these?
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
Well, I don't really see replacing DisplayTextToPlayer with BJDebugMsg as an improvement.
It's shorter by characters, but computationally more intensive as it calls DisplayTextToPlayer anyway (in a loop to all players)...

Though, less strings, less function calls and less string concatenations... that's an actual improvement.
And helps readability, both the code and in game.

Even better would be a solution that uses a somewhat different method.
 

Builder Bob

Live free or don't
Reaction score
249
Though, less strings, less function calls and less string concatenations... that's an actual improvement.
And helps readability, both the code and in game.

I guess everyone can judge for themselves then. Less strings can lead to more functions calls, and visa versa.

Here's a more modular approach which doesn't depend on substring positions. It doesn't display well in-game without using the log, and it's longer in some ways, but it was fun making it.
JASS:
function F takes nothing returns nothing
local string s="
local string s"
local string s1="function F takes nothing returns nothing"
local string s2="
call DisplayTextToPlayer(GetLocalPlayer(),0,0,s1+s+s3+s4+s+s4+s+I2S(1)+s3+s4+s1+s4+s+I2S(2)+s3+s4+s2+s4+s+I2S(3)+s3+s4+s3+s4+s+I2S(4)+s3+s4+s5+s4+s4+s+I2S(5)+s3+s4+s5+s5+s4+s2)
endfunction"
local string s3="="
local string s4="\""
local string s5="\\"
call DisplayTextToPlayer(GetLocalPlayer(),0,0,s1+s+s3+s4+s+s4+s+I2S(1)+s3+s4+s1+s4+s+I2S(2)+s3+s4+s2+s4+s+I2S(3)+s3+s4+s3+s4+s+I2S(4)+s3+s4+s5+s4+s4+s+I2S(5)+s3+s4+s5+s5+s4+s2)
endfunction
 

tom_mai78101

The Helper Connoisseur / Ex-MineCraft Host
Staff member
Reaction score
1,704
So that's how you call for the function in a trigger like that...

Reason? Good? What?

- Fun?
- Because you can?
- Keep people busy?
- Learn something new today?
- Because there's always a better way to do it?
- Because!

You're getting hyperactive here.
 

Builder Bob

Live free or don't
Reaction score
249
> ... Bob's

You can cut down on the SubString calls:
JASS:
function F takes nothing returns nothing
local string s="function F takes nothing returns nothing
local string s=\"\\
call DisplayTextToPlayer(GetLocalPlayer(),0,0,SubString(s,0,56) + SubString(s,56,57) + SubString(s,0,56) + SubString(s,57,58) + SubString(s,56,57) + SubString(s,57,58) + SubString(s,57,58) + SubString(s,58,999) + SubString(s,56,57) + SubString(s,58,999))
endfunction"
call DisplayTextToPlayer(GetLocalPlayer(),0,0,SubString(s,0,56) + SubString(s,56,57) + SubString(s,0,56) + SubString(s,57,58) + SubString(s,56,57) + SubString(s,57,58) + SubString(s,57,58) + SubString(s,58,999) + SubString(s,56,57) + SubString(s,58,999))
endfunction


Still the best so far... :p

Cut down the number of SubString calls even further.
JASS:
function F takes nothing returns nothing
local string s="function F takes nothing returns nothing
local string s=\"\\
call DisplayTextToPlayer(GetLocalPlayer(),0,0,SubString(s,0,57) + SubString(s,0,56) + SubString(s,57,58) + SubString(s,56,58) + SubString(s,57,347) + SubString(s,56,57) + SubString(s,58,347))
endfunction"
call DisplayTextToPlayer(GetLocalPlayer(),0,0,SubString(s,0,57) + SubString(s,0,56) + SubString(s,57,58) + SubString(s,56,58) + SubString(s,57,347) + SubString(s,56,57) + SubString(s,58,347))
endfunction
 

quraji

zap
Reaction score
144
AceHart..tsk. Trying to be sneaky with that edit?

At least you can delete that part of my post so I don't look like a fool :p
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • WildTurkey WildTurkey:
    is there a stephen green in the house?
    +1
  • 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 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