• Check out the results of the Techtree Contest #19!
  • 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.
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!

[General] Trigger editor and percent sign

Status
Not open for further replies.
Level 9
Joined
Jul 20, 2018
Messages
177
I created a function to cast doubles to integers in Lua. Here is the function:
Lua:
function cast_number(n)
    local s_e_m1, m2 = string.unpack('>I4I4', string.pack('>d', n))  -- two times I4 because WC3 supports only 4-byte integers
    return s_e_m1 >> 31, string.format('%03x', s_e_m1 >> 20 & 0x7ff), string.format('%05x%08x', s_e_m1 & 0xfffff, m2)
end
In Lua console function works as expected. Although, in WC3 the function returns complete garbage. I exported script using the editor and got this:
Lua:
function cast_number(n)
    local s_e_m1, m2 = string.unpack('>I4I4', string.pack('>d', n))
    return s_e_m1 >> 31, string.format('00a', s_e_m1 >> 20 & 0x7ff), string.format('b1c26af000000020', s_e_m1 & 0xfffff, m2)
end
Why my formatted strings got replaced with some garbage?
 
I read similar threads, there are some problems with % in trigger editor. You need to duplicate it (in string literals at least).

The only special meaning of % connected with tooltips is <rawcode,filedcode,%>. Such "code" in tooltips takes value of field fieldcode from rawcode and multiplies it by 100. But I do not think that these somehow influence on Trigger Editor.
 
I've literally just encountered this myself. This makes any meaningful usage of string.format in Lua impossible, because it crashes WorldEdit upon map save:
Lua:
function dummy()
    print("%s") -- crashes on save
end
Workaround:
Lua:
function dummy()
    print("\37s") -- works fine
end
 
@Luashine when you save map, Trigger Editor converts all double percents to a single one. Type inside it print(string.format("%%s", "Hello")) then open terrain editor File -> Export Script -> select where to save the file. Open it, and you will see that all %% are %.

And that's why it is better to use external code editors and some builders. When you add .lua file to map manually, you do not need to double persents, this is required only for code inside Trigger Editor.
 
Status
Not open for further replies.
Back
Top