Some examples of some codes that I could not find examples
Moderator: Forum Moderators
Forum rules
- Please use [code] BBCode tags in your posts for embedding WML snippets.
- To keep your code readable so that others can easily help you, make sure to indent it following our conventions.
Some examples of some codes that I could not find examples
Sometimes there is help in wiki, but it's not always clear and easy to understand so I have to look for examples in google etc.. And I often don't find anything.. So I spend hours to trying to make something work and I hope if I share my results it could help somebody.
1)
You are storing leaders of all sides to get a list of side numbers like "1,2,3,4" to be able to write a message to a random player side that still has leader alive (canrecruit=yes)
1)
[set_variable] [join]
creating a coma separated list of text from array..You are storing leaders of all sides to get a list of side numbers like "1,2,3,4" to be able to write a message to a random player side that still has leader alive (canrecruit=yes)
Code: Select all
...
[store_unit]
[filter]
canrecruit=yes
[/filter]
variable=mmbe_sides_alive ## name of your array that contains all sides leaders that are still alive
[/store_unit]
[set_variable]
name=test_list ## your new array where will be a text list of sides of these leaders eg. "1,2,3,4,5"
[join]
variable=mmbe_sides_alive ## the array name where it will be getting information from
key=side ## this is the sub name/key of array.. and it will get all values from ".side"
## like if you done {FOREACH mmbe_sides_alive i} and were storing info from each mmbe_sides_alive[$i].side
separator=, ## what you want to use as a separator in your list.. "1,2,3,4,5" so "," is for comma separated list
[/join]
[/set_variable]
{VARIABLE_OP test_value rand ($test_list)} ## extracting random side number from "1,3,4,7,9" array
[message]
side_for=$test_value ## sending message to that side
message="$test_list" ## and the message contains our result string that we were able to use to get random number from
[/message]
...
Re: Some examples of some codes that I could not find exampl
2) post your multiplayer add-on, creating _server.pbl file..
You may create the era or map.. and then.. question! How to post it to add-on server!?
You need to make file named "_server.pbl" and modify it using some text editor..
An example will look like this:
For example current topic ID is "46377" you will find it inside the whole topic link:
This file should be in your add-on folder, same place where is "_main.cfg"
If you don't have _main.cfg then you need to make it!
Inside it will look like this:
And finally.. You need to post it.. Go to you wesnoth... in menu chose "add-ons" -> "connect" -> click "downloads" column.. maybe click again.. until you see green text saying "Publish: New Settlers", click it.. read it.. agree to it if you agree to it.. and that should be it!
If there is a problem posting, check your _server.pbl file, make sure it doesnt have broken quotes... .. I mean... quotes that repeat 3 times instead of 2.. etc.. like so
It's all very simple.. but wasn't that easy to find _server.pbl example when I was starting.. had to write my own.. You can just copy/paste and modify mine.. Hope it helps somebody!
PS. and that's the link on proper way to do it (Wesnoth wiki) and there is an example of _server.pbl file as well in the end:
https://wiki.wesnoth.org/PBLWML
PPS. and there is my post on how to make scenario for a map and example of _main.cfg file.
http://forums.wesnoth.org/viewtopic.php ... 57#p618057
You may create the era or map.. and then.. question! How to post it to add-on server!?
You need to make file named "_server.pbl" and modify it using some text editor..
An example will look like this:
Code: Select all
title="New Settlers"
type="map_pack"
icon="units/human-peasants/peasant-attack2.png~FL(horiz)
version="0.0.1"
author="enclave"
passphrase="12345"
description="There are 4 resources. Gold, Stone, Wood and Food. 3 Factions: Humans, Elves and Orcs.
Peasants can build villages, walls, towers. Mages can research new technologies. Then you can recruit army and navy to fight your enemies on different maps, including historical ones.
It is recommended to play New Settlers on specially designed NS Random Maps, but New Settlers should be able to run on any map from any era.
"
email="boom@boom.boom"
[feedback]
topic_id=41751
[/feedback]
http://forums.wesnoth.org/viewtopic.php?f=21&t=46377
This file should be in your add-on folder, same place where is "_main.cfg"
If you don't have _main.cfg then you need to make it!
Inside it will look like this:
Code: Select all
#ifdef MULTIPLAYER
##Config files with main codes
{~add-ons/New_Settlers/macros/}
{~add-ons/New_Settlers/macros/2016jan/Diplomacy_Era}
##MAPS
{~add-ons/New_Settlers/scenarios/NS_Isar_Cross_with_Zombies.cfg}
{~add-ons/New_Settlers/scenarios/NS_South_Europe.cfg}
{~add-ons/New_Settlers/scenarios/NS_Ironcladkitty_Wonderland_3p.cfg}
{~add-ons/New_Settlers/scenarios/NS_4p_A_New_Land.cfg}
## Main cfg with events
{~add-ons/New_Settlers/mods/new_settlers.cfg}
#endif
If there is a problem posting, check your _server.pbl file, make sure it doesnt have broken quotes... .. I mean... quotes that repeat 3 times instead of 2.. etc.. like so
"I go to school" when I sleep"
. I avoid using single quote.. just in case.. but there may be no issues with it.. just me. So if it doesnt let you upload your addon, change description of your addon from "didn't"
into "didnt"
etc.. read everything carefully. There may be silly errors that make no sense.. like "failed to connect to server" but the truth is that you just have double quotes somewhere in a wrong place.It's all very simple.. but wasn't that easy to find _server.pbl example when I was starting.. had to write my own.. You can just copy/paste and modify mine.. Hope it helps somebody!
PS. and that's the link on proper way to do it (Wesnoth wiki) and there is an example of _server.pbl file as well in the end:
https://wiki.wesnoth.org/PBLWML
PPS. and there is my post on how to make scenario for a map and example of _main.cfg file.
http://forums.wesnoth.org/viewtopic.php ... 57#p618057
Last edited by Ravana on August 8th, 2017, 5:13 pm, edited 1 time in total.
Reason: Better use [code] for multilinestring
Reason: Better use [code] for multilinestring
Re: Some examples of some codes that I could not find examples
Sometimes you may come across the problem when you are trying to load your saved add-on and the save file will be marked "invalid" in red color.
Happened to me at least twice.. Quite a mysterious thing.. Because the code works, no problems whatsoever.. You didn't even notice when it happened to your add-on, until you tried to save and reload it. Now, CRAP, what to do and how to fix it?
In my last project I had to remove event by event to find the buggy place.. until I was finally able to reload my saved game.
And I found that the problem was hiding inside the short code:
First I tried to disable with "#" the
And strangely it fixed the problem, BUT while I was looking at code and refreshing my wesnoth I noticed the REAL PROBLEM, it was hiding in another bit of code..
If you look at it, u may notice that the array has no value......
it should be
This was a mistake in my coding, but it was working fine for some reason.. I guess it was automatically finding the value or what..
but when it came to save-loading it was treated as invalid save file..
OK. so I changed the
into
so if you have unfinished arrays anywhere... like:
be careful and now if you came across this problem, you have a clue where to start looking... your problem might be same as I had..
Happened to me at least twice.. Quite a mysterious thing.. Because the code works, no problems whatsoever.. You didn't even notice when it happened to your add-on, until you tried to save and reload it. Now, CRAP, what to do and how to fix it?
In my last project I had to remove event by event to find the buggy place.. until I was finally able to reload my saved game.
And I found that the problem was hiding inside the short code:
Code: Select all
[if]
[variable]
name=qc_system.humans.techs[$t1r_tech_counter].unit[$t1r_unit_counter]
not_equals=" "
[/variable]
[then]
{VARIABLE qc_system.humans.units[$qc_system.humans.shortcuts.units.$qc_system.humans.techs[$t1r_tech_counter].unit[$t1r_unit_counter].codename].sides[$side_number].enabled true}
[/then]
[/if]
{VARIABLE...
part as I thought maybe it's bloody too long for it to work somehow...And strangely it fixed the problem, BUT while I was looking at code and refreshing my wesnoth I noticed the REAL PROBLEM, it was hiding in another bit of code..
name=qc_system.humans.techs[$t1r_tech_counter].unit[$t1r_unit_counter]
If you look at it, u may notice that the array has no value......
it should be
name=qc_system.humans.techs[$t1r_tech_counter].unit[$t1r_unit_counter].codename
or unit[x].__value
or something.. This was a mistake in my coding, but it was working fine for some reason.. I guess it was automatically finding the value or what..
but when it came to save-loading it was treated as invalid save file..
OK. so I changed the
name=qc_system.humans.techs[$t1r_tech_counter].unit[$t1r_unit_counter]
into
name=qc_system.humans.techs[$t1r_tech_counter].unit[$t1r_unit_counter].codename
and the save became VALID now.. so if you have unfinished arrays anywhere... like:
array[i]
and NOT array[i].name
it may cause some deep bugs, which may magically appear or disappear depending on other parts of codes.. (like here, i removed {VARIABLE..
inside the [then][/then]
tags and savefile became VALID, while the bug was still there hiding.. be careful and now if you came across this problem, you have a clue where to start looking... your problem might be same as I had..
Re: Some examples of some codes that I could not find examples
1.13 raises that as immediate error.