• 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.
  • 💡 We're thrilled to announce that our upcoming texturing contest is in the works, and we're eager to hear your suggestions! Please take this opportunity to share your ideas in this theme discussion thread for the Texturing Contest #34!
  • 🏆 Hive's 7th HD Modeling Contest: Icecrown Creature is now open! The frozen wastes of Icecrown are home to some of Azeroth’s most terrifying and resilient creatures. For this contest, your challenge is to design and model a HD 3D monster that embodies the cold, undead, and sinister essence of Icecrown! 📅 Submissions close on April 13, 2025. Don't miss this opportunity to let your creativity shine! Enter now and show us your frozen masterpiece! 🔗 Click here to enter!

[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?
 
Level 9
Joined
Jul 20, 2018
Messages
177
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.
 
Level 20
Joined
Jan 3, 2022
Messages
364
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
 
Level 9
Joined
Jul 20, 2018
Messages
177
@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.
Top