Bug - bad hogs positioned cause in game input do not respond

10 replies [Last post]
francot514
User offline. Last seen 2 years 5 weeks ago. Offline
Joined: 2015-03-20
Posts: 163

Hey, im testing custom missions, and when i try to position hogs in the air (wrong position i think) the game input do not respond and i need to leave mission...

Wuzzy
Wuzzy's picture
User offline. Last seen 28 weeks 5 hours ago. Offline
Joined: 2012-06-20
Posts: 1304

Could you post a demo / replay please on http://www.hedgewars.org/demos ?

Are you telling us that you try to create your own missions and fail to get hog placement to work properly? In that case, it would be much more helpful if you posted the source code for reviewing.

Hi, I am a Hedgewars developer. Smile

francot514
User offline. Last seen 2 years 5 weeks ago. Offline
Joined: 2015-03-20
Posts: 163

You mean i need to post mission code like this:

Quote:
AddTeam(loc("Gunners"),16711680,"Badger","CakeR","Classic",0)
player = AddHog(loc("Fifi"),0,100,"4gsuif")
SetGearPosition(player, 374, 230)

Dont know how to create demo, but what happen is that if hedgegod is positioned in mid air or againts map collision the firts turn never start..

Wuzzy
Wuzzy's picture
User offline. Last seen 28 weeks 5 hours ago. Offline
Joined: 2012-06-20
Posts: 1304

First, I need to point out some mistakes in your code:

Quote:
AddTeam(loc("Gunners"),16711680,"Badger","CakeR","Classic",0)

The final letter in the fort file name (minus file suffix) is either “R” or “L” for the right or left version of the fort. In AddTeam, the fort name is specified without this extra letter. So in this case, use simply "Cake".

The flag argument must be a string or nil, don't use a number, please. The default flag is called “hedgewars” and shows a hedgehog on black background. If you use nil (or just 5 arguments anyways), the default flag is used. You find the flags in Data/Graphics/Flags of your Hedgewars installation.

Hint: While your color number is not wrong at all, I want to point out that you can also specify colors in hexadecimal notation, which is much easier to use IMO, just prepend the number with “0x”. By the way, 16711680 == 0xFF0000, the color red.

The “corrected” version of your AddTeam function call:

Quote:
AddTeam(loc("Gunners"),0xFF0000,"Badger","Cake","Classic")

Also, note that AddTeam only works when called inside onGameInit. Read here for the full documentation: http://hedgewars.org/kb/LuaAPI

Quote:
Dont know how to create demo,

Demos are automatically created after you played a game and did not abort it. Demos are saved in Demos/ inside your Hedgewars user directory, neatly sorted by date and time.

Hi, I am a Hedgewars developer. Smile

francot514
User offline. Last seen 2 years 5 weeks ago. Offline
Joined: 2015-03-20
Posts: 163

Quote:
The final letter in the fort file name (minus file suffix) is either “R” or “L” for the right or left version of the fort. In AddTeam, the fort name is specified without this extra letter. So in this case, use simply "Cake".

Ok, i do not discuss about that mistake, but that do not help solving the problem... After the game message "fight", there is nothing you can do for moving, if i remove line SetGearPosition() the problem is solved, then there should be something wrong in that function...

francot514
User offline. Last seen 2 years 5 weeks ago. Offline
Joined: 2015-03-20
Posts: 163

This is the image for clarify error, i cant start mission becuase it.

Wuzzy
Wuzzy's picture
User offline. Last seen 28 weeks 5 hours ago. Offline
Joined: 2012-06-20
Posts: 1304

So let me get this straight: You can not start the mission because the hogs you placed with AddHog just float in the air and don't drop. Is this correct?

In any case, we need to see your full Lua source code in order to help you.

I have no clue right now why this is happening.

Hi, I am a Hedgewars developer. Smile

francot514
User offline. Last seen 2 years 5 weeks ago. Offline
Joined: 2015-03-20
Posts: 163

Ok, here is the mission code, i have checked for errors:

Edit: it only works if removed SetGearPosition functions

Quote:
HedgewarsScriptLoad("/Scripts/Locale.lua")

local player = nil
local player2 = nil
local enemy = nil

function onGameInit()
Map = "Bamboo"
Theme = "Nature"
Seed = 0
GameFlags=gfBorder+gfSolidLand
TurnTime = 45 * 1000
SetGravity(0)
Ready = 5000
CaseFreq = 0
MinesNum = 5
MinesTime = 3
MineDudPercent = 0
Explosives = 0

AddTeam(loc("Gunners"),16711680,"Badger","Cake","Default")
player = AddHog(loc("Fifi"),0,100,"NoHat")

player2 = AddHog(loc("Good Dude"), 0, 90, "NoHat")


AddTeam(loc("Enemy"), 1175851, "Simple", "Island", "Default")
enemy = AddHog("Bad Guy", 1, 40, "NoHat")
SetGearPosition(player, 374, 230)
SetGearPosition(player2, 1512, 310)
SetGearPosition(enemy, 1612, 310)
end

function onGameStart()
ShowMission(loc("Test Mission"), loc("Test the mission script"), loc("Eliminate enemies."), 1, 0)

end

function onAmmoStoreInit()
SetAmmo(amGrenade, 9, 0, 0, 1)
SetAmmo(amParachute, 1, 0, 0, 1)
SetAmmo(amFirePunch, 0, 0, 0, 3)
SetAmmo(amBazooka, 9, 0, 0, 1)
SetAmmo(amBlowTorch, 0, 0, 0, 1)
SetAmmo(amShotgun, 0, 0, 0, 1)
SetAmmo(amSkip, 9, 0, 0, 0)
end

Wuzzy
Wuzzy's picture
User offline. Last seen 28 weeks 5 hours ago. Offline
Joined: 2012-06-20
Posts: 1304

It's no surprise your hedgehogs are floating in the air without dropping. You used SetGravity(0), which means the gravity is set to 0%. In other words: Your hogs are in spaaaace! Big Grin

Note that the game won't continue while the hogs are in mid-air. Hedgewars waits until all hogs stand on solid ground. Since this never happens, nothing happens.

The fix would be to remove SetGravity(0) from the script for default gravity. Or set the gravity to a positive value (100 = normal gravity).

You also might reconsider the spawning positions of your hedgehogs.

Hi, I am a Hedgewars developer. Smile

francot514
User offline. Last seen 2 years 5 weeks ago. Offline
Joined: 2015-03-20
Posts: 163

Wuzzy allegedly wrote:

The fix would be to remove SetGravity(0) from the script for default gravity. Or set the gravity to a positive value (100 = normal gravity).

You also might reconsider the spawning positions of your hedgehogs.

Ok removing that code fixes the problem, and do of course hogs fall and take damage,but i got what expected, that i can place hog in any map position outside terrain. Just for testing, then how to change gravity to "Low"???

Wuzzy
Wuzzy's picture
User offline. Last seen 28 weeks 5 hours ago. Offline
Joined: 2012-06-20
Posts: 1304

There are two possibilities to set gravity to “low”.

Either add “EnableGameFlags(gfLowGravity)” in onGameInit or add SetGravity(50) somewhere in code.

The first approach only works in onGameInit and as far I know, it cannot be disabled later in game. gfLowGravity corresponds to the “low gravity” symbol in the game scheme editor. It will also remove the low gravity utility from game.

The second approach works almost everywhere in the code (I guess) and you can theoretically change the gravity multiple times with SetGravity.

SetGravity simply sets the gravity to the percentage you provide it. SetGravity(100) means 100% gravity, SetGravity(50) means 50% gravity (same as in low gravity mode).

Hi, I am a Hedgewars developer. Smile

User login

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