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

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,494
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,494
> 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,494
> 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,667
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,494
> 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,494
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,494
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,667
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.
  • The Helper The Helper:
    The bots will show up as users online in the forum software but they do not show up in my stats tracking. I am sure there are bots in the stats but the way alot of the bots treat the site do not show up on the stats
  • Varine Varine:
    I want to build a filtration system for my 3d printer, and that shit is so much more complicated than I thought it would be
  • Varine Varine:
    Apparently ABS emits styrene particulates which can be like .2 micrometers, which idk if the VOC detectors I have can even catch that
  • Varine Varine:
    Anyway I need to get some of those sensors and two air pressure sensors installed before an after the filters, which I need to figure out how to calculate the necessary pressure for and I have yet to find anything that tells me how to actually do that, just the cfm ratings
  • Varine Varine:
    And then I have to set up an arduino board to read those sensors, which I also don't know very much about but I have a whole bunch of crash course things for that
  • Varine Varine:
    These sensors are also a lot more than I thought they would be. Like 5 to 10 each, idk why but I assumed they would be like 2 dollars
  • Varine Varine:
    Another issue I'm learning is that a lot of the air quality sensors don't work at very high ambient temperatures. I'm planning on heating this enclosure to like 60C or so, and that's the upper limit of their functionality
  • Varine Varine:
    Although I don't know if I need to actually actively heat it or just let the plate and hotend bring the ambient temp to whatever it will, but even then I need to figure out an exfiltration for hot air. I think I kind of know what to do but it's still fucking confusing
  • The Helper The Helper:
    Maybe you could find some of that information from AC tech - like how they detect freon and such
  • Varine Varine:
    That's mostly what I've been looking at
  • Varine Varine:
    I don't think I'm dealing with quite the same pressures though, at the very least its a significantly smaller system. For the time being I'm just going to put together a quick scrubby box though and hope it works good enough to not make my house toxic
  • Varine Varine:
    I mean I don't use this enough to pose any significant danger I don't think, but I would still rather not be throwing styrene all over the air
  • The Helper The Helper:
    New dessert added to recipes Southern Pecan Praline Cake https://www.thehelper.net/threads/recipe-southern-pecan-praline-cake.193555/
  • The Helper The Helper:
    Another bot invasion 493 members online most of them bots that do not show up on stats
  • Varine Varine:
    I'm looking at a solid 378 guests, but 3 members. Of which two are me and VSNES. The third is unlisted, which makes me think its a ghost.
    +1
  • The Helper The Helper:
    Some members choose invisibility mode
    +1
  • The Helper The Helper:
    I bitch about Xenforo sometimes but it really is full featured you just have to really know what you are doing to get the most out of it.
  • The Helper The Helper:
    It is just not easy to fix styles and customize but it definitely can be done
  • The Helper The Helper:
    I do know this - xenforo dropped the ball by not keeping the vbulletin reputation comments as a feature. The loss of the Reputation comments data when we switched to Xenforo really was the death knell for the site when it came to all the users that left. I know I missed it so much and I got way less interested in the site when that feature was gone and I run the site.
  • Blackveiled Blackveiled:
    People love rep, lol
    +1
  • The Helper The Helper:
    The recipe today is Sloppy Joe Casserole - one of my faves LOL https://www.thehelper.net/threads/sloppy-joe-casserole-with-manwich.193585/
  • The Helper The Helper:
    Decided to put up a healthier type recipe to mix it up - Honey Garlic Shrimp Stir-Fry https://www.thehelper.net/threads/recipe-honey-garlic-shrimp-stir-fry.193595/
  • The Helper The Helper:
    Here is another comfort food favorite - Million Dollar Casserole - https://www.thehelper.net/threads/recipe-million-dollar-casserole.193614/

      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