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
249
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,712
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,712
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.
  • 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
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top