Lua: Questions

68 replies [Last post]
Lyberta
Lyberta's picture
User offline. Last seen 3 years 32 weeks ago. Offline
Joined: 2016-09-10
Posts: 177

I'm trying to resurrect hedgehogs that are drowning, is it possible?

UltiMaxKom
UltiMaxKom's picture
User offline. Last seen 4 years 12 weeks ago. Offline
Joined: 2016-06-26
Posts: 381

POSSIBLE !

Remember this : "Impossible is Im-Possible" meaning NO IMPOSSIBLE Things

Include that drowning hoggies, i do it for fun (NO SCRIPTs)

But yeah, my method not FULLY right with your questions, i mean i only resurrect DEAD Hogs (automatically), not the drowning,,, its has only limited customization options (i can say it,,, almost useless for this version, no offense)

But if you asking about doing it with scripts, maybe asking Mikade/others who experts or Dev. is good (PM?) too,,,

╟───NW──────┼──────N╢

╓──────────────────╖ ╓──────────────────╖
⠀HP: ██████████ 1E9/1E91E9/1E9 ██████████ :MP
╙──────────────────╜ ╙──────────────────╜

Lyberta
Lyberta's picture
User offline. Last seen 3 years 32 weeks ago. Offline
Joined: 2016-09-10
Posts: 177

Here's what I have so far:

function onGameTick()
	for i, hog in ipairs(hogs) do
		if band(GetState(hog), gstDrowning) ~= 0 then
			local x = GetX(hog);
			local y = GetY(hog);
			y = y - 500;
			SetGearPosition(hog, x, y);
			SetState(hog, band(GetState(hog), bnot(gstDrowning + gstHHDeath)));
			SetEffect(hog, heResurrectable, 1);
		end
	end
end

It teleports hogs higher and seems to undo the state but hogs are now floating in the air and disappear after a few seconds.

UltiMaxKom
UltiMaxKom's picture
User offline. Last seen 4 years 12 weeks ago. Offline
Joined: 2016-06-26
Posts: 381

nice one,,,

we need ask Dev. is there a way to resurrect "DROWNING HOG" Back to the HELL,,,

please just drown you hoggies Big Grin

But its possible with Lua,,, developers make it available in the Gamestyle costumization

╟───NW──────┼──────N╢

╓──────────────────╖ ╓──────────────────╖
⠀HP: ██████████ 1E9/1E91E9/1E9 ██████████ :MP
╙──────────────────╜ ╙──────────────────╜

Lyberta
Lyberta's picture
User offline. Last seen 3 years 32 weeks ago. Offline
Joined: 2016-09-10
Posts: 177

SetEffect(hog, heResurrectable, 1);

This will make hog resurrectable if called before it drowns, but I need to make it drown based on a condition.

UltiMaxKom
UltiMaxKom's picture
User offline. Last seen 4 years 12 weeks ago. Offline
Joined: 2016-06-26
Posts: 381

Try to make that hog go to the land mass if it go to certain point, i mean above the water (little bit before it gone drown, don't make it drown first, it will disappear like you saying)
i mean,,, (detail) if the hog above the water (maybe 2 pixel above the water, use Lua with Y Cordinates of the regular water level + SD Water Rise) ,,, make him/she go to the land again to make that hog not "Drowning" ,,, why must drowning first ? i think it better if we not let him drowned,,, Annoyed

|{

╟───NW──────┼──────N╢

╓──────────────────╖ ╓──────────────────╖
⠀HP: ██████████ 1E9/1E91E9/1E9 ██████████ :MP
╙──────────────────╜ ╙──────────────────╜

Lyberta
Lyberta's picture
User offline. Last seen 3 years 32 weeks ago. Offline
Joined: 2016-09-10
Posts: 177

Hogs can bounce off water. The position check will need to emulate the game code. Maybe I need to look at the source code and redo it in Lua...

UltiMaxKom
UltiMaxKom's picture
User offline. Last seen 4 years 12 weeks ago. Offline
Joined: 2016-06-26
Posts: 381

right !
why i never think of it ?
Then re-place that hog,,,

maybe i help with this little thing :
Try look at your Scheme,,, you can set "Al Respawn on Death" option
which makes the Al Hog being respawned on the land again after drowned,,, and its the same hog !!!

this maybe can be your reference to find it,,, how to make those hoggies not drowning

btw,,, is we the HW Member active left ? no just a joke Big Grin
hope another people comment and help you, than just me,,,

|{

╟───NW──────┼──────N╢

╓──────────────────╖ ╓──────────────────╖
⠀HP: ██████████ 1E9/1E91E9/1E9 ██████████ :MP
╙──────────────────╜ ╙──────────────────╜

Lyberta
Lyberta's picture
User offline. Last seen 3 years 32 weeks ago. Offline
Joined: 2016-09-10
Posts: 177

function onGearAdd(gear)
	if GetGearType(gear) == gtHedgehog then
		SetEffect(gear, heResurrectable, 1);
	end
end

This will make all hogs respawn indefinitely but I want them to respawn only if they are drowning and have some health left.

UltiMaxKom
UltiMaxKom's picture
User offline. Last seen 4 years 12 weeks ago. Offline
Joined: 2016-06-26
Posts: 381

This is the solution
is this topic ended ?

╟───NW──────┼──────N╢

╓──────────────────╖ ╓──────────────────╖
⠀HP: ██████████ 1E9/1E91E9/1E9 ██████████ :MP
╙──────────────────╜ ╙──────────────────╜

nemo
nemo's picture
User offline. Last seen 1 week 3 days ago. Offline
Joined: 2009-01-28
Posts: 1861

FaTony allegedly wrote:

function onGearAdd(gear)
	if GetGearType(gear) == gtHedgehog then
		SetEffect(gear, heResurrectable, 1);
	end
end

This will make all hogs respawn indefinitely but I want them to respawn only if they are drowning and have some health left.

So.. we have an onGearDamage function... You could remove heResurrectable if the damage will set the hog's health below 0. That way any drowning respawn would still work, but hogs would still die normally.

--
Oh, what the heck. 1PLXzL1CBUD1kdEWqMrwNUfGrGiirV1WpH <= tip a hedgewars dev

Lyberta
Lyberta's picture
User offline. Last seen 3 years 32 weeks ago. Offline
Joined: 2016-09-10
Posts: 177

Ah yes, exactly.

Lyberta
Lyberta's picture
User offline. Last seen 3 years 32 weeks ago. Offline
Joined: 2016-09-10
Posts: 177

Hmm, when I call GetHealth() during OnGearDamage I still get the health at the start of a turn, I will have to keep track of damage taken during the whole turn.

nemo
nemo's picture
User offline. Last seen 1 week 3 days ago. Offline
Joined: 2009-01-28
Posts: 1861

FaTony allegedly wrote:

Hmm, when I call GetHealth() during OnGearDamage I still get the health at the start of a turn, I will have to keep track of damage taken during the whole turn.

So, Damage accumulates until it is applied. You're right that onGearDamage only gives the *current* damage.
However, GetGearValues in 0.9.22 *does* expose the accumulated Damage. So you can use that to avoid needing to maintain your own counter.
https://hedgewars.org/kb/LuaAPI#GetGearValues(gearUid)_(0.9.22)

--
Oh, what the heck. 1PLXzL1CBUD1kdEWqMrwNUfGrGiirV1WpH <= tip a hedgewars dev

Lyberta
Lyberta's picture
User offline. Last seen 3 years 32 weeks ago. Offline
Joined: 2016-09-10
Posts: 177

That doesn't work during onGearResurrect().

mikade
mikade's picture
User offline. Last seen 13 weeks 2 days ago. Offline
Joined: 2010-10-22
Posts: 355

Is there a specific reason why you want to resurrect them?

Why don't you just use scheme to turn on bottom / side borders? That will prevent hogs dying via drowning, (and obviously they'll still die from normal damage). Gameplay-wise that sounds like what you're trying to do, and won't require any scripts.

mikade
Hedgewars Developer

UltiMaxKom
UltiMaxKom's picture
User offline. Last seen 4 years 12 weeks ago. Offline
Joined: 2016-06-26
Posts: 381

mikade allegedly wrote:

Is there a specific reason why you want to resurrect them?

Why don't you just use scheme to turn on bottom / side borders? That will prevent hogs dying via drowning, (and obviously they'll still die from normal damage). Gameplay-wise that sounds like what you're trying to do, and won't require any scripts.

.........
Why i never thinking about it ?
simple and everyone can +without content for requirement for everyone to play,,,

thats sounds good but maybe he want to make the game don't make the hog die by drowning,,, and without the border that maybe annoying to be added,,,

and oh hey !!! Mikade ? ^^ i glad see an experts again here Big Grin

╟───NW──────┼──────N╢

╓──────────────────╖ ╓──────────────────╖
⠀HP: ██████████ 1E9/1E91E9/1E9 ██████████ :MP
╙──────────────────╜ ╙──────────────────╜

nemo
nemo's picture
User offline. Last seen 1 week 3 days ago. Offline
Joined: 2009-01-28
Posts: 1861

FaTony allegedly wrote:

That doesn't work during onGearResurrect().

Was this in response to stripping resurrection flag immediately after lethal damage? Why would that need to work during onGearResurrect?

--
Oh, what the heck. 1PLXzL1CBUD1kdEWqMrwNUfGrGiirV1WpH <= tip a hedgewars dev

Lyberta
Lyberta's picture
User offline. Last seen 3 years 32 weeks ago. Offline
Joined: 2016-09-10
Posts: 177

I need to set their previous health during resurrection.

nemo
nemo's picture
User offline. Last seen 1 week 3 days ago. Offline
Joined: 2009-01-28
Posts: 1861

FaTony allegedly wrote:

I need to set their previous health during resurrection.

Oh. The problem isn't removing resurrection, it's knowing what their health was on impact with the water?

Didn't realise you were on some other problem.

Yeah, for that you'd need to add damage tracking, since the resurrect callback occurs after the health is reset.

Or I guess check hog health in onGameTick20 which would probably be right most of the time ☺

--
Oh, what the heck. 1PLXzL1CBUD1kdEWqMrwNUfGrGiirV1WpH <= tip a hedgewars dev

Lyberta
Lyberta's picture
User offline. Last seen 3 years 32 weeks ago. Offline
Joined: 2016-09-10
Posts: 177

So i'm trying to hook the creation of piano and graves here's what I have:

function onHogAttack(ammotype)
	if ammotype == amPiano then
		logger.Output("PIANO STRIKE!"); --works
		numbombs = maxbombs;
	end
end

function onGearAdd(gear)
	if GetGearType(gear) == gtPiano then
		logger.Output("GETTING DELETED"); --doesn't
		DeleteGear(gear);
		logger.Output("DELETED");
	end
end

Same with graves:

function onGeadAdd(gear)
	if GetGearType(gear) == gtGrave then
		logger.Output("Grave has been created."); --doesn't work
		table.insert(graves, gear);		
	end
end

nemo
nemo's picture
User offline. Last seen 1 week 3 days ago. Offline
Joined: 2009-01-28
Posts: 1861

So.... that last function has a typo... You realise that right?

--
Oh, what the heck. 1PLXzL1CBUD1kdEWqMrwNUfGrGiirV1WpH <= tip a hedgewars dev

Lyberta
Lyberta's picture
User offline. Last seen 3 years 32 weeks ago. Offline
Joined: 2016-09-10
Posts: 177

Oh, didn't see it. Thanks. Now I'm trying to teleport graves that are underwater, here's what I have:

function thismodule.onGameTick()
	for i, grave in ipairs(graves) do
		local y = GetY(grave);
		if y > WaterLine then
			logger.Output("Teleporting grave.");
			FindPlace(grave, true, 0, LAND_WIDTH);
		end
	end
end

This has the same problem as with drowning hedgehogs, graves still disappear.

nemo
nemo's picture
User offline. Last seen 1 week 3 days ago. Offline
Joined: 2009-01-28
Posts: 1861

FaTony allegedly wrote:

Oh, didn't see it. Thanks. Now I'm trying to teleport graves that are underwater, here's what I have:
function thismodule.onGameTick()
	for i, grave in ipairs(graves) do
		local y = GetY(grave);
		if y > WaterLine then
			logger.Output("Teleporting grave.");
			FindPlace(grave, true, 0, LAND_WIDTH);
		end
	end
end

This has the same problem as with drowning hedgehogs, graves still disappear.

Soooo. might want to log what those y/waterline levels are.. Don't see any obvious reason for that to fail..

One tiny possibility is that you are on a level with opaque water like, oh, Compost and UnderWater - play is a bit faster on those since drowning animation is skipped. But it miiiight mean onGameTick gets called after the grave is already killed.

Can't think of anything else. FindPlace should work on graves like anything else. No special cases to my knowledge. If it is the thing above, maybe teleport it while it is still a couple of pixels above the waterline

Maybe make sure that module onGameTick up there is actually being called?

Oh... one other thought. If you give graves submersible attribute, they can go a lot further down before getting killed. This would avoid the problems above, and even make onGameTick20 reasonable for lighter call.

--
Oh, what the heck. 1PLXzL1CBUD1kdEWqMrwNUfGrGiirV1WpH <= tip a hedgewars dev

Lyberta
Lyberta's picture
User offline. Last seen 3 years 32 weeks ago. Offline
Joined: 2016-09-10
Posts: 177

So I'm trying to get the health of a hedgehog and here's the code I have:

function GetHogHealth(gear)
	if GetGearType(gear) ~= gtHedgehog then
		return nil;
	end
	local health = GetHealth(gear);
	local values = {GetGearValues(gear)};
	return health - values[12];
end

But for some reason it reports health that is lower than the real value. Help?

KoBeWi
KoBeWi's picture
User offline. Last seen 4 hours 42 min ago. Offline
Joined: 2010-12-25
Posts: 564

Depends on where you use the function.
E.g. the value you get during OnGearDamage is the value after damage applied, so you need to add damage to get the current health.

Lyberta
Lyberta's picture
User offline. Last seen 3 years 32 weeks ago. Offline
Joined: 2016-09-10
Posts: 177

GetGearValues returns the damage.

KoBeWi
KoBeWi's picture
User offline. Last seen 4 hours 42 min ago. Offline
Joined: 2010-12-25
Posts: 564

I don't know what the "damage" value does.

GetHealth should return the currently displayed health. HOWEVER, inside OnGearDamage function, it returns the new health, before the value above Hedgehog is updated. So you'd need to add the damage argument from OnGearDamage to get the currently displayed health. If you call GetHealth OUTSIDE OnGearDamage it should work just fine, without adding/subtracting anything, like you do now with GetGearValues.
(I'm not an expert, explaining your problem more could help)

Lyberta
Lyberta's picture
User offline. Last seen 3 years 32 weeks ago. Offline
Joined: 2016-09-10
Posts: 177

I'm calling this onGameTick. I need to track health increased by vampire too.

KoBeWi
KoBeWi's picture
User offline. Last seen 4 hours 42 min ago. Offline
Joined: 2010-12-25
Posts: 564

Sooo...

function onGameTick()
AddCaption(GetHogHealth(CurrentHedgehog));
end

This works for me (always shows the current health, both after damage and vampire). You probably have a more complicated use, but I can't think of one that could break it. Maybe you modify the health manually or... I don't know.

Lyberta
Lyberta's picture
User offline. Last seen 3 years 32 weeks ago. Offline
Joined: 2016-09-10
Posts: 177

Yeah, I use it too. It breaks after several thousand vampire buff points.

Lyberta
Lyberta's picture
User offline. Last seen 3 years 32 weeks ago. Offline
Joined: 2016-09-10
Posts: 177

What's the variable of the spawn health?

UltiMaxKom
UltiMaxKom's picture
User offline. Last seen 4 years 12 weeks ago. Offline
Joined: 2016-06-26
Posts: 381

A allegedly wrote:

I Popup for a moment [2016/12/9]
Popup from sleep almost 2 weeks in a row...
Then i see something, hope i can help,
FaTony allegedly wrote:

What's the variable of the spawn health?

What health ? a Health crates ?
What variable ? a variable which is the amount of a Health Crates ?

If a it was the Health Crates and The Variable of the amount for permanent (all crates is have the same amount except the Health crates that was setup to has a fixed amount), then i think it was "HealthCaseAmount = x" for a Default setup (onInit Only)
or when it was variable as chance of Health Crates then it was "HealthCaseProb = x" (onInit Only)
or when it was variable as the Amount of Health crates that can be changed everytime not just in onInit, then i think it was "SetHealth(gearUidofCrates, x)"

Without Quotes and "x" as your variable amount

Hope helpful and can solve it,
The best guess of me is "SetHealth(gearUid, x)"
Set its health = amount it give

]{

╟───NW──────┼──────N╢

╓──────────────────╖ ╓──────────────────╖
⠀HP: ██████████ 1E9/1E91E9/1E9 ██████████ :MP
╙──────────────────╜ ╙──────────────────╜

Lyberta
Lyberta's picture
User offline. Last seen 3 years 32 weeks ago. Offline
Joined: 2016-09-10
Posts: 177

I want the health of hogs at the start of the game. This:

function thismodule.onGearAdd(gear)
	if GetGearType(gear) == gtHedgehog then
		SetHealth(gear, 1000);
	end
end

crashes the game.

UltiMaxKom
UltiMaxKom's picture
User offline. Last seen 4 years 12 weeks ago. Offline
Joined: 2016-06-26
Posts: 381

FaTony allegedly wrote:

I want the health of hogs at the start of the game. This:
function thismodule.onGearAdd(gear)
	if GetGearType(gear) == gtHedgehog then
		SetHealth(gear, 1000);
	end
end

crashes the game.


oh,,,
Don't SetHealth(k,v) in onAddGear or other Early Initialization event (e.g : PlaySound(snd) in onGameInit) in Game Start / Too Early...

I Use another function to set Health on the start of the game though,
because yes, crashing nice when we set them on Early start of the game, i think its kinda buggy.

Instead, i use another function to setup things "Which Crash The Game When Used Too Early" like that...

My Actual (but Example) extra Init Function which executed after the game start :

function onGameStart()
   FirstSetup()
end

function FirstSetup()
   for k,v in pairs(AllHogs) do
      SetHealth(v, 1000)
   end
end

Its works Perfectly, but actually i use other System (Code above is example) to Initialize all the need of the game,,,
Maybe and hope can be an Example...

]{

╟───NW──────┼──────N╢

╓──────────────────╖ ╓──────────────────╖
⠀HP: ██████████ 1E9/1E91E9/1E9 ██████████ :MP
╙──────────────────╜ ╙──────────────────╜

KoBeWi
KoBeWi's picture
User offline. Last seen 4 hours 42 min ago. Offline
Joined: 2010-12-25
Posts: 564

I need something like onHogAttack, but called after hedgehog finishes his action, e.g. after two shots from shotgun etc.
AFAIK, it's not possible now, right? (not counting hard-coding every case)

Lyberta
Lyberta's picture
User offline. Last seen 3 years 32 weeks ago. Offline
Joined: 2016-09-10
Posts: 177

Does HW support modules? I was looking for a regex library written in Lua so I can properly parse script parameters and only ones I've found are implemented using modules.

nemo
nemo's picture
User offline. Last seen 1 week 3 days ago. Offline
Joined: 2009-01-28
Posts: 1861

Have you tried? Should work... But if you need regex maaaybe your script param needs changing Smile

There's already string splitting.

--
Oh, what the heck. 1PLXzL1CBUD1kdEWqMrwNUfGrGiirV1WpH <= tip a hedgewars dev

Lyberta
Lyberta's picture
User offline. Last seen 3 years 32 weeks ago. Offline
Joined: 2016-09-10
Posts: 177

Is there a way to indicate optional parts and capture them as submatches using only standard library? Haven't found it.

Lyberta
Lyberta's picture
User offline. Last seen 3 years 32 weeks ago. Offline
Joined: 2016-09-10
Posts: 177

Modules don't work which is a shame. A lot of code requires them.

nemo
nemo's picture
User offline. Last seen 1 week 3 days ago. Offline
Joined: 2009-01-28
Posts: 1861

I can't think of any reason modules wouldn't work. Maybe you should post the HWP you tried creating.
As for "sub portions", this is from one of the existing parameter scripts. The gravity modifier.
function onParameters()
parseParams()
gravity = tonumber(params["g"]) or gravity

Here's a sample line from one of my schemes.
g=-50,g2=150,period=5000,script2=Highlander

it's comma separated. using params["g"] params["g2"].. etc (in this case gravity shifting from -50 to 150% every 5 seconds, playing Highlander)

--
Oh, what the heck. 1PLXzL1CBUD1kdEWqMrwNUfGrGiirV1WpH <= tip a hedgewars dev

Lyberta
Lyberta's picture
User offline. Last seen 3 years 32 weeks ago. Offline
Joined: 2016-09-10
Posts: 177

Ok, here's the multiplayer game style:

local test = require "foo";

function onGameStart()
	test.bar();
end

And here's the module:

local foo = {};

function foo.bar()
	AddCaption("Hello world");
end

return foo;

I've tried all directories and I never see the text.

For the parameters, I use this:

function onParameters()
	if ScriptParam == nil then
		return
	end
	for modulename in string.gmatch(ScriptParam, "[%w_]+") do
		HedgewarsScriptLoad("/Scripts/Modules/" .. modulename .. ".lua");
	end
end

This correctly parses "A B C" into "A", "B" and "C". Now I want to pass parameters to scripts like "A(B = C) B(C D E) F" so it would parse as "A(B = C)" with submatch "B = C", "B(C D E)" with submatch "C D E", and "F" with no submatch.

nemo
nemo's picture
User offline. Last seen 1 week 3 days ago. Offline
Joined: 2009-01-28
Posts: 1861

It'd be nice if you could link to the exact replicate hwp so I could see precisely how you set it up for possible fixes/workarounds. My guesses are load error or load order error but hard to say. Maybe it isn't possible, but can't think of any reason why that would be.

Also, I really don't get why you're doing that parsing. Why not stick to the comma separated that parseparams already uses? Seems needlessly complicated.

--
Oh, what the heck. 1PLXzL1CBUD1kdEWqMrwNUfGrGiirV1WpH <= tip a hedgewars dev

Lyberta
Lyberta's picture
User offline. Last seen 3 years 32 weeks ago. Offline
Joined: 2016-09-10
Posts: 177

nemo allegedly wrote:

It'd be nice if you could link to the exact replicate hwp so I could see precisely how you set it up for possible fixes/workarounds. My guesses are load error or load order error but hard to say. Maybe it isn't possible, but can't think of any reason why that would be.

Also, I really don't get why you're doing that parsing. Why not stick to the comma separated that parseparams already uses? Seems needlessly complicated.

I don't have hwp yet. I've just put Test.lua into Data/Script/Multiplayer and foo.lua in Data, Data/Scripts and Data/Scripts/Multiplayer. The documentation says that you need to put module into the same directory as your lua file so I've tried all dirs.

For the parameters it's much easier to type A B C instead of script1=A, script2=B, script3=C etc. In my styles I may load up to 15 scripts at once.

nemo
nemo's picture
User offline. Last seen 1 week 3 days ago. Offline
Joined: 2009-01-28
Posts: 1861

Ok, now I'm just really confused.
String.gmatch (which you're using above and the existing param parse uses too), can split on whitespace just as easily as commas.

So... Why do you need another regex module?

You may not have an hwp yet, but if you want people to reproduce, it'd be nice if you'd provide a simple self-contained test zip, rather than making me copy and paste off a forum and hope it happens to match *exactly* what you're doing.

Reduces error is all...

--
Oh, what the heck. 1PLXzL1CBUD1kdEWqMrwNUfGrGiirV1WpH <= tip a hedgewars dev

Lyberta
Lyberta's picture
User offline. Last seen 3 years 32 weeks ago. Offline
Joined: 2016-09-10
Posts: 177

Alright, here's the thorough explanation. I have a modular game style that loads other scripts, I have no idea what those scripts do because it is assumed that other people write them. Currently, I have no way of communicating script parameters to those scripts because Lua standard library doesn't have proper regex.

Here's the script parameter from the scheme that I usually play with:

FaTony OP MegaHealth NoWaterDeath ExplosiveDeath CakeZooka UltimateMudball NapalmNade MineCheese EvilPoison HellishPistol MineCake PoisonMine NuclearMelon MelonStrike

It loads 15 lua scripts (FaTony.lua, OP.lua, MegaHealth.lua, etc) and they all are engaged.

Now suppose I want to add Game Hacks to that list. Game Hacks use script parameter to control the script, so I would like to type:

FaTony OP MegaHealth NoWaterDeath ExplosiveDeath CakeZooka UltimateMudball NapalmNade MineCheese EvilPoison HellishPistol MineCake PoisonMine NuclearMelon MelonStrike GameHacks(saucerfuel=200%, ready=10s, stickyminetimer=750, nojump=true)

This would load Game Hacks to pass saucerfuel=200%, ready=10s, stickyminetimer=750, nojump=true as script parameter. That would be very easy with regex because I would just make a capture group. It is much harder without regex.

nemo
nemo's picture
User offline. Last seen 1 week 3 days ago. Offline
Joined: 2009-01-28
Posts: 1861

Personally I would do it like this if I wanted to avoid regex.
Replace: FaTony OP MegaHealth NoWaterDeath ExplosiveDeath CakeZooka UltimateMudball NapalmNade MineCheese EvilPoison HellishPistol MineCake
PoisonMine NuclearMelon MelonStrike GameHacks(saucerfuel=200%, ready=10s, stickyminetimer=750, nojump=true)

With: FaTony OP MegaHealth NoWaterDeath ExplosiveDeath CakeZooka UltimateMudball NapalmNade MineCheese EvilPoison HellishPistol MineCake
PoisonMine NuclearMelon MelonStrike GameHacks(saucerfuel=200%,ready=10s,stickyminetimer=750,nojump=true)

Split on spaces, then ().
That's just me tho. Bonus, takes up less space ☺
But... The default Lua string split does in fact take patterns. so you could split on space without a comma in front first...
[^,]%s
Then split on ().
http://lua-users.org/wiki/PatternsTutorial
http://lua-users.org/wiki/StringLibraryTutorial

Also. You know we have a length limit right?

The example you gave is perilously close to max on it.
You might also want to encourage people use the shorter GameHacks param values.
But stripping the spaces would at least reduce that.

--
Oh, what the heck. 1PLXzL1CBUD1kdEWqMrwNUfGrGiirV1WpH <= tip a hedgewars dev

Lyberta
Lyberta's picture
User offline. Last seen 3 years 32 weeks ago. Offline
Joined: 2016-09-10
Posts: 177

nemo allegedly wrote:
Also. You know we have a length limit right?

The example you gave is perilously close to max on it.
You might also want to encourage people use the shorter GameHacks param values.
But stripping the spaces would at least reduce that.

That is unfortunate, in my own software I put a 64 bit size of the string first so I can have 2^64 char strings.

nemo
nemo's picture
User offline. Last seen 1 week 3 days ago. Offline
Joined: 2009-01-28
Posts: 1861

yeeeaaah. preeeeetty sure your program would crash on string of length 2^32 much less one a billion times larger than that Smile
But the reason in this case would be that unc0rr is using pascal short string which uses first byte for size of string.

Would require a rewrite of all that, and there hasn't been much pressure to change that for network protocol in particular where average string is a byte or two in length...
Splitting message is an easy enough option if anyone actually wants to do it. But if you're getting this complex w/ script param, might make more sense to focus on a lua config tab to game setup. could parse a config file for setup, or read it from the script itself. Friendlier to the user.
The param option was more just a quick hack catchall unc0rr slapped in than intended to hold large amounts of data.

Heck. Can't imagine UI being usable w/ a string even a few thousand chars long.

--
Oh, what the heck. 1PLXzL1CBUD1kdEWqMrwNUfGrGiirV1WpH <= tip a hedgewars dev

Lyberta
Lyberta's picture
User offline. Last seen 3 years 32 weeks ago. Offline
Joined: 2016-09-10
Posts: 177

Well, in ideal world you would have a GUI framework in Lua that will draw config tab at runtime. So then I could make subtab for each module and let them draw into their tabs. There seems to be a Lua bindings for Qt so I guess it's very much possible to do. I just don't have time to do this myself as I always have a huge backlog of personal projects.

nemo allegedly wrote:

yeeeaaah. preeeeetty sure your program would crash on string of length 2^32 much less one a billion times larger than that Smile
But the reason in this case would be that unc0rr is using pascal short string which uses first byte for size of string.

#include "limits" // angle brackets are eaten by the forum engine.
#include "string"

int main(int argc, char* argv[])
try
{
	std::string s;
	// 1 page more than a typical 32 bit app would be able to allocate.
	s.resize(std::numeric_limits*ANGLE BRACKET*std::uint32_t*ANGLE BRACKET*::max() + 4096LL);
	std::cin.get();
}

Easily allocated more than 4 GiB of RAM. We live in 64 bit world. All pointers and sizes are 64 bit wide. I only use 32 bit sizes to be compatible with old 90s formats like RIFF or MIDI.

nemo
nemo's picture
User offline. Last seen 1 week 3 days ago. Offline
Joined: 2009-01-28
Posts: 1861

not everything is 64 bit yet. Hedgewars still has a ridiculously wide range of compatibility. Heck we still support 512 textures just for szczur.

--
Oh, what the heck. 1PLXzL1CBUD1kdEWqMrwNUfGrGiirV1WpH <= tip a hedgewars dev

User login

Copyright © 2004-2024 Hedgewars Project. All rights reserved. [ contact ]