Dixie's Lua Thread

Discussion of Lua and LuaWML support, development, and ideas.

Moderator: Forum Moderators

User avatar
Dixie
Posts: 1757
Joined: February 10th, 2010, 1:06 am
Location: $x1,$y1

Re: Dixie's Lua Thread

Post by Dixie »

That's what I did. Unless you have access to a second laptop/computer. I find it better if you can play by yourself instead of relying on somebody else, because it's easier to track bug reports, and you automatically see what's sync and how.

About the Lua not being basic: maybe you are right and I am too modest, I thought of my skills in Lua as being not that high overall. Hope you can figure it out, I tried to leave some comments around, but maybe they're not enough, I dunno. Just ask if there's something unclear :)
Jazz is not dead, it just smells funny - Frank Zappa
Current projects: Internet meme Era, The Settlers of Wesnoth
Anonymissimus
Inactive Developer
Posts: 2461
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: Dixie's Lua Thread

Post by Anonymissimus »

I've gotten over the sow_set_goal functionality a few times without out of sync now (sow_game_stats.goal identical on both clients); by converting the function to wml.
(It is often not sensible to code strings-heavy things in lua due to wmllint's spellcheck etc). However,

@Dixie
What did that do ?:

Code: Select all

--~ 	if goal and goal < 0 then
--~ 		wesnoth.set_variable("sow_game_stats.goal", goal)
--~ 	else
sow_set_goal is only called once with argument 10 so it's useless.

Is it the way it's supposed to be that all sow_game_stats.player.valid fields show as true (although I've reduced human player number to 2 if in debug mode, to speed up the testing process) ?
What else could I do to speed testing up, do I really need to reconnect with the host every time wml has changed ? (testing wml changes, not lua)

[message]side_for= doesn't seem to have any effect here, it shows only for the host (or maybe side=1).
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml startersPlan Your Advancements: mp mod
The Earth's Gut: sp campaignSettlers of Wesnoth: mp scenarioWesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
User avatar
Dixie
Posts: 1757
Joined: February 10th, 2010, 1:06 am
Location: $x1,$y1

Re: Dixie's Lua Thread

Post by Dixie »

Hmm, maybe I forgot something with the side_for.
Is it the way it's supposed to be that all sow_game_stats.player.valid fields show as true (although I've reduced human player number to 2 if in debug mode, to speed up the testing process) ?

Checking if the player was valid in sow_set_goal was in case someone started a game without a player 1, so that the first player to actually have a turn would set the game's goal. I don't know to what extent it's needed. I (or you) should try it with no player 1, to see what happens.
The way to control the number of players is to set non-needed player slots to "Empty". In sow_mapgen, it checks and places all sides' variable sow_game_stats.player.valid with controller "null" as false. I couldn't check if it was "human", because other clients show as "network", not "human", depending on what client you check with. AIs are also only AIs for the host, they are "network" for other clients. So it led to all manners of OOS errors. Checking whether the sides are false or valid is important for a bunch of stuff, like determining the amount of player and generating map, rolling the die only on side turns with a human player, etc.

Code: Select all

--~    if goal and goal < 0 then
--~       wesnoth.set_variable("sow_game_stats.goal", goal)
--~    else
The thing about "goal and goal > 0" was because at first, the function didn't have any argument: I wanted to player to pick between 8, 10 and 12. For the sake of testing, I added that argument, so that if it was nil, the message would come up, else if it was an integer, it would put that value as the game goal.

For the sake of speeding up... to the best of my knowledge, if you change WML, you have to bring back both clients to the title screen and reload the cache. Maybe only the host is needed, though, I dunno, but I did both.

Hope this helps :) Thanks again!
Jazz is not dead, it just smells funny - Frank Zappa
Current projects: Internet meme Era, The Settlers of Wesnoth
Anonymissimus
Inactive Developer
Posts: 2461
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: Dixie's Lua Thread

Post by Anonymissimus »

Dixie wrote: The way to control the number of players is to set non-needed player slots to "Empty".
Is this something that you do somewhere in the code, or is this done only in the UI (by the host, when starting the game ?)

By the way, I think I really want to take it; but expect your codings to be edited rather mercylessly. :P
If I'm ever going to maintain a mp addon it needs to be such a building-type of addon.

EDIT
Instead of the first, use the second structure:

Code: Select all

		if a then
		else
			if b then
			else
			end
		end

		if a then
		elseif b then
		else
		end
And resource is spelled with a single s :P.

What are the dev_... variables for (does dev mean development) ?

And sorry, I really don't like writing end end end end etc, honestly, how do you understand which block-closing belongs to which block opening...?
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml startersPlan Your Advancements: mp mod
The Earth's Gut: sp campaignSettlers of Wesnoth: mp scenarioWesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
User avatar
Dixie
Posts: 1757
Joined: February 10th, 2010, 1:06 am
Location: $x1,$y1

Re: Dixie's Lua Thread

Post by Dixie »

Anonymissimus wrote:
Dixie wrote: The way to control the number of players is to set non-needed player slots to "Empty".
Is this something that you do somewhere in the code, or is this done only in the UI (by the host, when starting the game ?)
I'm not sure I understand what you mean by "in the UI", but it's this part, at the top of sow_mapgen()

Code: Select all

	-- Determining amount of players, Generating Variables, Placing Labels, Removing Shroud
	game_stats = {dev_used=false, goal=0, free_road=0, players_qty=0, map=""}
	table.insert(game_stats, {"trade",{ active=false, side=0, accepted=0, {"offer",{}}, {"demand",{}} }})
	table.insert(game_stats, {"player",{ valid=false }})
	for i,v in ipairs(wesnoth.sides) do
		if i ~= 9 then
			if v.controller ~= "null" then
				-- Creating variable
				table.insert(game_stats, {"player",{ valid=true, {"ressources",{lumber=0,wool=0,grain=0,brick=0,ore=0}},
				{"development",{victory=0,monopoly=0,road=0,plenty=0,knight=0}},
				{"victory",{points=0, road=0, knight=0}} }})
				game_stats.players_qty = game_stats.players_qty + 1

				-- Placing labels & icons
				wesnoth.fire("label", {x=sow_labels.player[i].x, y=sow_labels.name, color=sow_labels.player[i].color, text=sow_labels.player[i].name})
				wesnoth.fire("label", {x=sow_labels.player[i].x, y=sow_labels.victory, color=sow_labels.player[i].color, text="0"})
				wesnoth.fire("label", {x=sow_labels.player[i].x, y=sow_labels.ressources, color=sow_labels.player[i].color, text="0"})
				wesnoth.fire("label", {x=sow_labels.player[i].x, y=sow_labels.development, color=sow_labels.player[i].color, text="0"})
				wesnoth.fire("label", {x=sow_labels.player[i].x, y=sow_labels.longest, color=sow_labels.player[i].color, text="0"})
				wesnoth.fire("label", {x=sow_labels.player[i].x, y=sow_labels.largest, color=sow_labels.player[i].color, text="0"})
				wesnoth.fire("label", {x=sow_labels.player[i].x, y=sow_labels.lumber, color=sow_labels.player[i].color, text="0"})
				wesnoth.fire("label", {x=sow_labels.player[i].x, y=sow_labels.grain, color=sow_labels.player[i].color, text="0"})
				wesnoth.fire("label", {x=sow_labels.player[i].x, y=sow_labels.wool, color=sow_labels.player[i].color, text="0"})
				wesnoth.fire("label", {x=sow_labels.player[i].x, y=sow_labels.brick, color=sow_labels.player[i].color, text="0"})
				wesnoth.fire("label", {x=sow_labels.player[i].x, y=sow_labels.ore, color=sow_labels.player[i].color, text="0"})
				
				wesnoth.add_tile_overlay(sow_labels.player[i].x, sow_labels.lumber, {image="items/lumber.png"} )
				wesnoth.add_tile_overlay(sow_labels.player[i].x, sow_labels.grain, {image="items/grain.png"} )
				wesnoth.add_tile_overlay(sow_labels.player[i].x, sow_labels.wool, {image="items/wool.png"} )
				wesnoth.add_tile_overlay(sow_labels.player[i].x, sow_labels.brick, {image="items/brick.png"} )
				wesnoth.add_tile_overlay(sow_labels.player[i].x, sow_labels.ore, {image="items/ore.png"} )
				
			else
				table.insert(game_stats, {"player",{ valid=false }})
				wesnoth.put_unit(sow_labels.player[i].x, sow_labels.name)
			end
Anonymissimus wrote: By the way, I think I really want to take it; but expect your codings to be edited rather mercylessly. :P
If I'm ever going to maintain a mp addon it needs to be such a building-type of addon.
Bah, I don't mind, at this point. I might even learn a thing or two :) If I hadn't wanted it to be edited, I wouldn't have uploaded it like this.
Anonymissimus wrote: What are the dev_... variables for (does dev mean development) ?
Yes, it was shorter :)
Anonymissimus wrote: And sorry, I really don't like writing end end end end etc, honestly, how do you understand which block-closing belongs to which block opening...?
Well, I only did it when I had a bunch of "if ... then ... else if ... then ... else if ... then ..." etc. I wouldn't do it for more complex/diverse blocks, but feel free to do it any other way ;)
Jazz is not dead, it just smells funny - Frank Zappa
Current projects: Internet meme Era, The Settlers of Wesnoth
Anonymissimus
Inactive Developer
Posts: 2461
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: Dixie's Lua Thread

Post by Anonymissimus »

UI = user interface; the host can select for the eight players slots whether they shall be network players or empty (or himself or anything) when starting the game

EDIT
At the start of sow_new_side_turn you do
wesnoth.set_variable(string.format("sow_game_stats.dev_used", false))
which is wrong, what should that be ? (Don't understand your semantics good enough yet.)
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml startersPlan Your Advancements: mp mod
The Earth's Gut: sp campaignSettlers of Wesnoth: mp scenarioWesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
User avatar
Dixie
Posts: 1757
Joined: February 10th, 2010, 1:06 am
Location: $x1,$y1

Re: Dixie's Lua Thread

Post by Dixie »

About the UI thing: it is indeed controlled by the host in the UI. Maybe it would be more intuitive to do it in the code, though? I dunno, but feel free to change it if you think it should be. Maybe it should, I'm not sure. The current method can surely lead to confusion the first time the add-on is played, in any case, but it was the way that felt the simplest to me.
Anonymissimus wrote: EDIT
At the start of sow_new_side_turn you do
wesnoth.set_variable(string.format("sow_game_stats.dev_used", false))
which is wrong, what should that be ? (Don't understand your semantics good enough yet.)
Well, maybe I did this in reverse, I dunno. Basically, a player can only use a single development card per turn (In the official rules, it can't be one that was bought that same turn, but this wasn't implemented... yet?). So when a dev card is used, sow_game_stats.dev_used is set to true. And when you are attempting to use one, the function will check wether or not dev_used is true or false. If true, it will prevent you from accessing the menu which lets you pick a development card to use from your hand. And of course, at each new turn, this variable has to be set to false, else if a player uses a dev card, all following players will be prevented from using any. Am I making myself clear?
Jazz is not dead, it just smells funny - Frank Zappa
Current projects: Internet meme Era, The Settlers of Wesnoth
Anonymissimus
Inactive Developer
Posts: 2461
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: Dixie's Lua Thread

Post by Anonymissimus »

Dixie wrote:Well, maybe I did this in reverse, I dunno. Basically, a player can only use a single development card per turn (In the official rules, it can't be one that was bought that same turn, but this wasn't implemented... yet?). So when a dev card is used, sow_game_stats.dev_used is set to true. And when you are attempting to use one, the function will check wether or not dev_used is true or false. If true, it will prevent you from accessing the menu which lets you pick a development card to use from your hand. And of course, at each new turn, this variable has to be set to false, else if a player uses a dev card, all following players will be prevented from using any. Am I making myself clear?
Yes, very clear.

My general strategy is to deactivate everything that's not needed and readd it one by one and testing (also for OOS). I've understood and cleaned up in some parts the map generation algorithm, next is the first houses and roads functionalities. When only the complete trading system and dev cards remain it may be time for an upload, what do you think ? Since it's better to have something small that works instead of something big which doesn't.
I guess we have a severe problem with the trading system since side_for + [option] in [message] causes OOS (no matter whether wml or helper.get_user_choice etc): http://gna.org/bugs/?17350
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml startersPlan Your Advancements: mp mod
The Earth's Gut: sp campaignSettlers of Wesnoth: mp scenarioWesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
User avatar
Dixie
Posts: 1757
Joined: February 10th, 2010, 1:06 am
Location: $x1,$y1

Re: Dixie's Lua Thread

Post by Dixie »

I think the latest update (the one you have, unless I'm mistaken, since I haven't done anything on the add-on since putting it on here) for the trading system had changed the system, though. Instead of having "side_for"s with options, I had the trading player select we he offered and asked for, ended his turn, and some boolean was checked at each new side_turn to see if trade was underway. If not, a normal turn ebgins, if so, he was asked if he accepted the trade. If accepted, no other side could accept. And side_turns were ended until we were back to the trading player, so he could end his turn. Gameplay-wise, this shouldn't be much of a problem: trade should be agreed for on the chat before sending it to others anyway. It's a bit like the ATB mod works, which inspired me. Turns are gonna fly by, but there shouldn't really be a maximum, as far as I know.

About your way of testing: of course, it is very sensible. I did this too at first in local multiplayer to make sure everything worked, but I didn't rthink I'd encounter that much OOS. I was kinda retesting everything one by one too, but was stuck at the beginning with not much time left.
Jazz is not dead, it just smells funny - Frank Zappa
Current projects: Internet meme Era, The Settlers of Wesnoth
Anonymissimus
Inactive Developer
Posts: 2461
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: Dixie's Lua Thread

Post by Anonymissimus »

major succes:
I've brought the random building of initial settlements/roads into sync by creating a custom side end turn event which is fired at the next side turn, with appropriate custom turn_number and side_number variables. It looks as if the wrong player would build the stuff but this is currently probably the only way to solve this - AND once that side end turn is synched by the engine it will be rather easy to remove the custom side end turn events.

I've made some other rather structural changes:
The initial resources are now the ones needed to build 2 settles and 2 roads; this may not quite comply with the rules, but it makes the code much easier and I can display nice float labels so that new players learn quickly what resources the stuff costs. ;)
I've written a function that gets the numerical data from sow_game_stats and updates the display for all values and all players; thats cleaner this way instead of updating various single labels (although less efficient); it'll replace the other updates.

Btw, there is a [event][filter_condition] tag in 1.9, to greatly simplify some of your events.
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml startersPlan Your Advancements: mp mod
The Earth's Gut: sp campaignSettlers of Wesnoth: mp scenarioWesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
User avatar
Dixie
Posts: 1757
Joined: February 10th, 2010, 1:06 am
Location: $x1,$y1

Re: Dixie's Lua Thread

Post by Dixie »

Seems cool! Good job with everything! Maybe when everything works, we can implement back the initial resource bonus of the first settlement's placement (which is a good bonus at game start). But I agree for now it can be placed aside, for the most important is having a solid, synced base.

Good job again! :) I'll be curious to see how it all looks! (But you don't have to hurry and update something, take the time you need to complete important stuff before)
Jazz is not dead, it just smells funny - Frank Zappa
Current projects: Internet meme Era, The Settlers of Wesnoth
Anonymissimus
Inactive Developer
Posts: 2461
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: Dixie's Lua Thread

Post by Anonymissimus »

Dixie wrote:Maybe when everything works, we can implement back the initial resource bonus of the first settlement's placement (which is a good bonus at game start). But I agree for now it can be placed aside, for the most important is having a solid, synced base.
You've misunderstood, that bonus is there. Although I wonder why the first settle gives resources at once but the second doesn't, so this is intentional ?
Currently I'm at the robber system; you've used side_for= key there to display choices for players out-of their side turn which can't work according to silene so that needs a complicated "a full game turn only for those queries" - structure too.

No worry, the better I understand that addon the more fun it is. I seriously don't think it would be possible without 1.9 or without lua, especially since side turn events aren't synched in 1.8.
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml startersPlan Your Advancements: mp mod
The Earth's Gut: sp campaignSettlers of Wesnoth: mp scenarioWesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
User avatar
Dixie
Posts: 1757
Joined: February 10th, 2010, 1:06 am
Location: $x1,$y1

Re: Dixie's Lua Thread

Post by Dixie »

Yes, I had forgotten about that robber thing, good catch!

About the bonus: In the normal board game, you start with three ressources, not six. They are the resources surrounding one of your two initial settlements, and although it is not specified it has to be the first one you place, I just decided that for the sake of simplicity (and it's the way me and my friends played it). I thought it made sense and was intuitive. But if you wish to add an option for the player to choose which of his first two settlements should give him his initial resources, I guess you might as well go ahead :)
Jazz is not dead, it just smells funny - Frank Zappa
Current projects: Internet meme Era, The Settlers of Wesnoth
User avatar
pauxlo
Posts: 1047
Joined: September 19th, 2006, 8:54 pm

Re: Dixie's Lua Thread

Post by pauxlo »

Dixie wrote:About the bonus: In the normal board game, you start with three ressources, not six. They are the resources surrounding one of your two initial settlements, and although it is not specified it has to be the first one you place, I just decided that for the sake of simplicity (and it's the way me and my friends played it).
In the rules I have, you get the resources of the second initial settlement, not the first. (The 10 years jubilee's edition, german.)

The second may be a bit more balanced, since this way the first player can't grab the best places and additionally already get those resources.
User avatar
Dixie
Posts: 1757
Joined: February 10th, 2010, 1:06 am
Location: $x1,$y1

Re: Dixie's Lua Thread

Post by Dixie »

Sounds reasonnable, although as a player I like to grab a good spot first and then a port afterwards. As far as it is coded, a player placing his ressource-giving initial settlement on the coast only starts with one or two resources, which is a disadvantage. Did your rules say anything about this? Did you double a resource at random or let the player be at a disadvatange resource-wise but owning a port?

Also, the first player can certainly grab the "best place" (which can often be subjective), but players place their settlements one at a time, so the "second-best place" is garanteed to fall in someone else's hands.
Jazz is not dead, it just smells funny - Frank Zappa
Current projects: Internet meme Era, The Settlers of Wesnoth
Post Reply