Lua Questions
Moderator: Forum Moderators
Re: Lua Questions
8680: Just out of curiosity, is there any reason you prefer semicolons over commas?
UMC Story Images — Story images for your campaign!
Re: Lua Questions
@Crendgrim: It's more that I prefer terminators over separators, and commas used as terminators just don't look right.
@battlestar: Note that you could use commas instead of all the semicolons except for the last one, and that you can omit a semicolon/comma when the next non-whitespace character is
@battlestar: Note that you could use commas instead of all the semicolons except for the last one, and that you can omit a semicolon/comma when the next non-whitespace character is
}
.- battlestar
- Posts: 690
- Joined: January 1st, 2007, 7:12 am
Re: Lua Questions
Thanks 8680.
Generally speaking, is a mixture of Lua and WML better than pure WML? I'm considering a piece of code that consist of a WML supra-structure with a few WML macros and a lot of macros containing Lua. Is that a good idea?
Generally speaking, is a mixture of Lua and WML better than pure WML? I'm considering a piece of code that consist of a WML supra-structure with a few WML macros and a lot of macros containing Lua. Is that a good idea?
LUA: Llama Under Apprenticeship
Hell faction: completed
Hell faction: completed
Re: Lua Questions
Yes, but a better idea would be to replace the WML macros containing Lua with WML tags implemented in Lua. See the Lua Pack for how to do this.
- battlestar
- Posts: 690
- Joined: January 1st, 2007, 7:12 am
Re: Lua Questions
Here're some choices (I already have written the WML for the menu interface that fires the macros that correspond to each attack):
-
electric mantle:
disarm:
Again, your help is much appreciated.
LUA: Llama Under Apprenticeship
Hell faction: completed
Hell faction: completed
- battlestar
- Posts: 690
- Joined: January 1st, 2007, 7:12 am
Re: Lua Questions
Hi,
8680 wrote this bit for me:
but I couldn't figure out how to use it even after looking at the luaWML wiki. Trying to use the value calculated by requiredXP(currentLevel) in [set_variable] or [modify_unit], to set the experience to level values.
Thanks
8680 wrote this bit for me:
Code: Select all
function requiredXP(currentLevel)
return currentLevel == 1 and 50 or
math.floor(requiredXP(currentLevel - 1) + 50 * (1.6 - math.log10(currentLevel)) + 0.5)
end
Thanks
LUA: Llama Under Apprenticeship
Hell faction: completed
Hell faction: completed
Re: Lua Questions
You’d need to call it from Lua. Here’s an (untested) WML tag interface.
I’ll keep doing small things like this, but I don’t think I’ll be fully participating in your project; it’s too far advanced; I think it might be easier for me to rewrite everything from scratch than jump in now.
Spoiler:
- battlestar
- Posts: 690
- Joined: January 1st, 2007, 7:12 am
Re: Lua Questions
Thanks again, this is the end product, and it's tested and working.
Spoiler:
LUA: Llama Under Apprenticeship
Hell faction: completed
Hell faction: completed
Re: Lua Questions
Put the
[lua]
tag in the campaign #ifdef
, it should be more efficient that way.- battlestar
- Posts: 690
- Joined: January 1st, 2007, 7:12 am
Re: Lua Questions
You changed the XP required to advance from level 1 to 115?
- battlestar
- Posts: 690
- Joined: January 1st, 2007, 7:12 am
Re: Lua Questions
Not really, turns out currentLevel that's fed into the function was actually the value of previous level, so now it's become:
Lvl 1: 50 (defined by unit file)
Lvl 2: 115 (return currentLevel == 1 and 115)
Lvl 3: 180 (first actual calculation)
Lvl 4: 236 (etc. by calculation)
I was having a little trouble with modifying the unit level before the level was fed into the function, and I figured it was very close to original values anyway... so I started working on something else.
I know I probably could've fixed it by moving two of those [set_variable] tags and split the [modify_unit] tag... >_>
Lvl 1: 50 (defined by unit file)
Lvl 2: 115 (return currentLevel == 1 and 115)
Lvl 3: 180 (first actual calculation)
Lvl 4: 236 (etc. by calculation)
I was having a little trouble with modifying the unit level before the level was fed into the function, and I figured it was very close to original values anyway... so I started working on something else.
Code: Select all
# TODO: consider combining with SCC_CHOOSE_UPG macro below
#define SCC_LEVEL_UP
[event]
name=post advance
first_time_only=no
[filter] # right after a unit with status isHero=yes advances
[filter_wml]
[status]
isHero=yes
[/status]
[/filter_wml]
[/filter]
[store_unit] # stored hero in question
[filter]
x,y=$x1,$y1
[/filter]
variable=upgrading_hero
[/store_unit]
[store_required_xp]
current_level=$upgrading_hero.level
variable=reqxp
[/store_required_xp]
[set_variable]
name=new_level
value=$upgrading_hero.level
[/set_variable]
[set_variable]
name=new_level
add=1
[/set_variable]
[modify_unit]
[filter]
id=$upgrading_hero.id
[/filter]
max_experience=$reqxp
level=$new_level
[/modify_unit]
{CLEAR_VARIABLE upgrading_hero}
{CLEAR_VARIABLE reqxp}
{CLEAR_VARIABLE new_level}
[/event]
#enddef
LUA: Llama Under Apprenticeship
Hell faction: completed
Hell faction: completed
Re: Lua Questions
I suppose I wasn’t clear enough originally, apologies.
requiredXP(currentLevel)
was supposed to return the XP required for a PC currently at level currentLevel
to advance to the next level. Here, I’ll extend the WML interface:
Spoiler:
- battlestar
- Posts: 690
- Joined: January 1st, 2007, 7:12 am
Re: Lua Questions
Thanks, I like your codes better. I'll implement them and consider level up "experience" determination codes done after testing. It's kind of a separate entity from level up "upgrades", which improves unit stats. The only thing shared between them is timing (both have event name=post advance).
For now, the main thing to code for is this:
"TODO: randomly choose 3 nonrepeating upgrades (with value >0 and <= max_upg_~~) from list of upgrades in the unit's [variables] tag and feed the upgrade names into variables: upg_choice_1, upg_choice_2, and upg_choice_3."
It's the main step for the level up upgrades. I'll leave that to you for whenever you're able to do it, thanks!
For now, the main thing to code for is this:
"TODO: randomly choose 3 nonrepeating upgrades (with value >0 and <= max_upg_~~) from list of upgrades in the unit's [variables] tag and feed the upgrade names into variables: upg_choice_1, upg_choice_2, and upg_choice_3."
It's the main step for the level up upgrades. I'll leave that to you for whenever you're able to do it, thanks!
LUA: Llama Under Apprenticeship
Hell faction: completed
Hell faction: completed