• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Is this possible

Status
Not open for further replies.
Of course, it depends on the exact effect you want. Example:
  • Tr
  • Events
    • Map Initialization
  • Conditions
  • Actions
    • Set Strings[1] = create
    • Set Strings[2] = kill
    • Set Strings[3] = sleep
For each (IntegerA) from 1 to 12, do (Actions)
Loop - Actions
Trigger - Add to Trigger2 <gen> the event (Player - Player(IntegerA) types a message containg <Empty string> as A Substring[/trigger]
  • Trigger2
  • Events
  • Conditions
  • Actions
    • If (All conditions are true) then do (Actions) else do (Actions)
      • If - Conditions
        • (Entered chat string) Equal to Strings[1]
      • Then - Actions
        • Set Point1 = (Center of (Playable Map Area))
        • Unit - Create 1 Footman for (Triggering player) at Point1
        • Custom script: call RemoveLocation (udg_Point1)
      • Else - Actions
        • If (All conditions are true) then do (Actions) else do (Actions)
          • If - Conditions
            • (Entered chat string) Equal to Strings[2]
          • Then - Actions
            • Unit - Kill (some unit)
Like this. In case you meant whatever you type to be presented on the screen, here is the trigger:
  • Tr
  • Events
    • Map Initialization
  • Conditions
  • Actions
    • For each (IntegerA) from 1 to 12, do (Actions)
      • Loop - Actions
        • Trigger - Add to Trigger2 <gen> the event (Player - Player(IntegerA) types a message containg <Empty string> as A Substring
  • Trigger2
  • Events
  • Conditions
  • Actions
    • Set String = (Entered chat string)
    • Custom script: call BJDebugMsg(udg_String)
 
This trigger must be named String if you want to test it out:

JASS:
function StringFunction takes nothing returns nothing
    call BJDebugMsg("String function executed :)")
endfunction
 
function StringActions takes nothing returns nothing
    //you must type as a chat string "StringFunction" for this to execute properly.
    call ExecuteFunc(GetEventPlayerChatString())
endfunction
 
function InitTrig_String takes nothing returns nothing
    local trigger t=CreateTrigger()
    call TriggerAddAction(t,function StringActions)
    call TriggerRegisterPlayerChatEvent(t,Player(0),"",false)
endfunction
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
If you're trying to type code into the game at run-time then you're pretty much going to have to parse it the same way a processor such as JassHelper does it. If the language you want to use to execute code is very simple, then it will be simple to process the information given.

If the user were to type "DoNothing" then you could do:

JASS:
ExecuteFunc("DoNothing")

Notice "DoNothing" could be referenced as GetEventPlayerChatString().

It would be more complicated for parameters, and you would need to use an assortment of global variables in order to "transfer" the parameter values. Let's say the user typed in: "FogEnable(false)" and you wanted to process that.

JASS:
globals
    boolean param
endglobals

local string chat = GetEventPlayerChatString()
local string func = null
local string parameter = null
local integer chatlength = StringLength(chat)
local integer i = 0

loop
    exitwhen(i == chatlength)
    if(SubString(chat, i, i+1)=="(") then
        set func = SubString(chat, 0, i)
        set parameter = SubString(chat, 0, i+2, chatlength-1)

        exitwhen(true)
    endif
    set i=i+1
endloop
if(func==null) then
    set func = chat
endif

//assign global parameter value
if(parameter=="true") then
    set param=true
else
    set param=false
endif
call ExecuteFunc(func)

Eh, the parameters are pretty difficult to transfer especially when non-declared functions like natives are used, since ExecuteFunc does not include any parameter values.

Also, there is no function in GUI equivalent to ExecuteFunc, so it would be pretty hard to accomplish.
 
Level 11
Joined
Mar 31, 2009
Messages
732
Jass is not an interpreted language, theres no simple way to be able to write code at run-time and expect it to be executed.

You could, however, design your own interpreter. Expect to spend a lot of time writing things like:
"if (String[1] == "GetPlayerId") then
return GetPlayerId(String[2])
endif"
and a thousand others for every function and parameter in the API. Pretty much would have to duplicate the entire API.
 
Status
Not open for further replies.
Top