Page 1 of 1

having trouble with counters xD

Posted: Sat Jan 11, 2014 10:43 am
by Dysoch
i got this:

Code: Select all

game.onevent(defines.events.onplayercrafteditem, function(event)
	if event.itemstack.name=="stone-gear-wheel" or event.itemstack.name=="iron-gear-wheel" or event.itemstack.name=="steel-gear-wheel" then
		if gears_counter == nil then gears_counter=1
		else gears_counter = gears_counter + event.itemstack.count end
	end
	if event.itemstack.name=="wooden-axe" or event.itemstack.name=="iron-axe" or event.itemstack.name=="steel-axe" or event.itemstack.name=="steel-axe2" or event.itemstack.name=="steel-axe3" then
		if mining_counter == nil then mining_counter=1
		else mining_counter = mining_counter + event.itemstack.count end
	end
	if event.itemstack.name=="sandwall" then
		if sand_counter == nil then sand_counter=1
		else sand_counter = sand_counter + math.random(500) end
	end
	if event.itemstack.name=="basic-mining-drill-sand" then
		if sand_counter == nil then sand_counter=1
		else sand_counter = sand_counter + math.random(500) end
		if gears_counter == nil then gears_counter=25
		else gears_counter = gears_counter + 25 end
		if mining_counter == nil then mining_counter=2
		else mining_counter = mining_counter + 2 end
	end
	if event.itemstack.name=="basic-mining-drill" then
		if gears_counter == nil then gears_counter=5
		else gears_counter = gears_counter + 5 end
		if mining_counter == nil then mining_counter=5
		else mining_counter = mining_counter + 5 end
	end
end)

game.onevent(defines.events.onplayermineditem, function(event)
	if event.itemstack.name=="sand" then
		if sand_counter == nil then sand_counter=1
		else sand_counter = sand_counter + event.itemstack.count
		end
	end
end)
i set it so, that when an counter is nil, it gets set to a number (differently depending on what you crafted or mined) and then i SHOULD keep counting them and adding them to counter.
but the problem is, (i tried with sand, didnt test others yet) that sand keeps its counter at nil, even when mining it xD

what to do?

btw, i also have this above it:

Code: Select all

gears_counter=0
sand_counter=0
mining_counter=0
tried it with and without, to no avail

Re: having trouble with counters xD

Posted: Sat Jan 11, 2014 1:05 pm
by SilverWarior
The problem in your code is that you are trying to set value to uninitialized variable.

Code: Select all

if SomeVariable == nill then do_something
When the above code will teturn True it means that the SomeVariable is not initialized. So before seting its value you need to initialize it or if we are talking about object you need to create it first.

What do you wanna achieve?

Re: having trouble with counters xD

Posted: Sat Jan 11, 2014 4:15 pm
by Dysoch
SilverWarior wrote:The problem in your code is that you are trying to set value to uninitialized variable.

Code: Select all

if SomeVariable == nill then do_something
When the above code will teturn True it means that the SomeVariable is not initialized. So before seting its value you need to initialize it or if we are talking about object you need to create it first.

What do you wanna achieve?
These counters are for my dynamic research. They worked before, (even with if nil then set number)
But for some reason they wont work anymore xD

Re: having trouble with counters xD

Posted: Sat Jan 11, 2014 9:15 pm
by ficolas
Cant look at it atm but you should make something like a debugger.
Everytime the player has crafts an item, print "crafted", print the name and the stack cound, then inside the if print "added", that way you know where the problem is.
Trying to teach you how to fish instead of giving you a fish :)

Re: having trouble with counters xD

Posted: Sat Jan 11, 2014 9:24 pm
by FreeER
ficolas wrote:Cant look at it atm but you should make something like a debugger.
Yes, this :) I would use game.player.print(serpent.block(gears_counter)) before and after the line that should update it, then spread out and test any other variables that you expect to change (maybe the event itself?), when you find what didn't change as you expected you know exactly where the issue is and it's much easier to test for what the issue is :)

Re: having trouble with counters xD

Posted: Sat Jan 11, 2014 10:54 pm
by Dysoch
Trying to teach you how to fish instead of giving you a fish
Hahah thx. I always wanted to know how to fish ;)

Ill try it in a few hours when im home

Re: having trouble with counters xD

Posted: Sun Jan 12, 2014 12:05 am
by Dysoch
ok its odd. when adding game.player.print(serpent.block(sand_counter)) to test the counters, it prints just fine and shows that the counter is increased when mined
but when typing game.player.print(serpent.block(sand_counter)) in the console, you will alwyas get nil xD

Re: having trouble with counters xD

Posted: Sun Jan 12, 2014 12:18 am
by FreeER
Dysoch wrote:but when typing game.player.print(serpent.block(sand_counter)) in the console, you will alwyas get nil xD
That's because the variables are completely separate for mods and console (to prevent being unable to use the same variable names as other mods). You'd need a script interface if you wanted to check that from the console :) So it's easier to just add some debug statements unless you expect trouble for several versions :D And even then you could have a glob.release variable and place those debug statements in an if conditional lol

Re: having trouble with counters xD

Posted: Sun Jan 12, 2014 12:20 am
by Dysoch
FreeER wrote:
Dysoch wrote:but when typing game.player.print(serpent.block(sand_counter)) in the console, you will alwyas get nil xD
That's because the variables are completely separate for mods and console (to prevent being unable to use the same variable names as other mods). You'd need a script interface if you wanted to check that from the console :) So it's easier to just add some debug statements unless you expect trouble for several versions :D And even then you could have a glob.release variable and place those debug statements in an if conditional lol
of course, makes sense xD

got it to work, but now i cant play due to core script error xD

Re: having trouble with counters xD

Posted: Sun Jan 12, 2014 12:25 am
by FreeER
Dysoch wrote:got it to work, but now i cant play due to core script error xD
Have fun fishing! But don't forget to ask others for good spots if the fish seem to disappear lol

Re: having trouble with counters xD

Posted: Sun Jan 12, 2014 12:25 am
by Dysoch
sigh. got another error. for some reason the counters get reset after a save. (set to nil)
then when an unlocker (dynamic research) checks its code, since i dont want any counters to be nil (got a global counter to add them all) it gives an error when running script and counter is nil.

anyway to keep counters when saving and loading?

Re: having trouble with counters xD

Posted: Sun Jan 12, 2014 12:29 am
by FreeER
Dysoch wrote:anyway to keep counters when saving and loading?
put them in the glob table (the only table that gets saved with the game as far as I know), if you don't want to keep them there for some reason you can use onsave and onload events I suppose (I've never tried)

Re: having trouble with counters xD

Posted: Sun Jan 12, 2014 12:35 am
by Dysoch
mmm odd, its appears its not the counter itself.
the error its gives is: attempted argument to compare number to nil (kinda weird error xD)
and the line it points to is this:

Code: Select all

if game.player.force.recipes["iron-gear-wheel"].enabled then return
the entire code: (its kinda long!)

Code: Select all

--[[Dynamic System Counters increase]]--
game.onevent(defines.events.onplayercrafteditem, function(event)
	if event.itemstack.name=="stone-gear-wheel" or event.itemstack.name=="iron-gear-wheel" or event.itemstack.name=="steel-gear-wheel" then
		if gears_counter == nil then gears_counter=1
		else gears_counter = gears_counter + event.itemstack.count end
	end
	if event.itemstack.name=="wooden-axe" or event.itemstack.name=="iron-axe" or event.itemstack.name=="steel-axe" or event.itemstack.name=="steel-axe2" or event.itemstack.name=="steel-axe3" then
		if mining_counter == nil then mining_counter=1 
		else mining_counter = mining_counter + event.itemstack.count end
	end
	if event.itemstack.name=="sandwall" then
		if sand_counter == nil then sand_counter=math.random(500)
		else sand_counter = sand_counter + math.random(500) end
	end
	if event.itemstack.name=="basic-mining-drill-sand" then
		if sand_counter == nil then sand_counter=math.random(500)
		else sand_counter = sand_counter + math.random(500) end
		if gears_counter == nil then gears_counter=25
		else gears_counter = gears_counter + 25 end
		if mining_counter == nil then mining_counter=2
		else mining_counter = mining_counter + 2 end
	end
	if event.itemstack.name=="basic-mining-drill" then
		if gears_counter == nil then gears_counter=5
		else gears_counter = gears_counter + 5 end
		if mining_counter == nil then mining_counter=5
		else mining_counter = mining_counter + 5 end
	end
end)

game.onevent(defines.events.onplayermineditem, function(event)
	if event.itemstack.name=="sand" then
		if sand_counter == nil then sand_counter=1
		else sand_counter = sand_counter + event.itemstack.count
			game.player.print(serpent.block(sand_counter))
		end
	end
end)

game.onevent(defines.events.ontick, function(event)
	if game.tick%3600==0 then
		if gears_counter == nil or sand_counter == nil or mining_counter == nil then 
		return else
			dytech_counter = gears_counter + sand_counter + mining_counter
		end
	end
	--[[Dynamic System unlocks]]--
	if event.tick%60==0 then
		--[[GEARS]]--
		if game.player.force.recipes["iron-gear-wheel"].enabled then return
		elseif gears_counter > math.random(75,200) then
			if math.random(1000)==1 then
				gears_counter =(gears_counter-math.random(25))
				game.player.print(game.gettext("msg-dynamic-failure"))
			else 
				game.player.force.recipes["iron-gear-wheel"].enabled = true
				game.player.print(game.gettext("msg-iron-gears"))
				game.player.force.resetrecipes()
			end
		end
		if game.player.force.recipes["steel-gear-wheel"].enabled then return
		elseif gears_counter > math.random(750,1250) then
			if math.random(500)==1 then
				gears_counter =(gears_counter-math.random(100))
				game.player.print(game.gettext("msg-dynamic-failure"))
			else 
				if game.player.force.technologies["steel-processing"].researched then
					game.player.force.recipes["steel-gear-wheel"].enabled = true
					game.player.print(game.gettext("msg-steel-gears"))
					game.player.force.resetrecipes()
				else return
				end
			end
		end
		--[[AXES]]--
		if game.player.force.recipes["iron-axe"].enabled then return
		elseif mining_counter > math.random(2,10) then
			if math.random(1000)==1 then
				mining_counter =(mining_counter-math.random(2))
				game.player.print(game.gettext("msg-dynamic-failure"))
			else 
				game.player.force.recipes["iron-axe"].enabled = true
				game.player.print(game.gettext("msg-iron-axe"))
				game.player.force.resetrecipes()
			end
		end
		if game.player.force.recipes["steel-axe"].enabled then return
		elseif mining_counter > math.random(10,25) then
			if math.random(800)==1 then
				mining_counter =(mining_counter-math.random(4))
				game.player.print(game.gettext("msg-dynamic-failure"))
			else 
				if game.player.force.technologies["steel-processing"].researched then
					game.player.force.recipes["steel-axe"].enabled = true
					game.player.print(game.gettext("msg-steel-axe"))
					game.player.force.resetrecipes()
				else return
				end
			end
		end
		if game.player.force.recipes["steel-axe2"].enabled then return
		elseif mining_counter > math.random(40,80) then
			if math.random(500)==1 then
				mining_counter =(mining_counter-math.random(10))
				game.player.print(game.gettext("msg-dynamic-failure"))
			else 
				game.player.force.recipes["steel-axe2"].enabled = true
				game.player.print(game.gettext("msg-adv-steel-axe"))
				game.player.force.resetrecipes()
			end
		end
		if game.player.force.recipes["steel-axe3"].enabled then return
		elseif mining_counter > math.random(90,125) then
			if math.random(250)==1 then
				mining_counter =(mining_counter-math.random(50))
				game.player.print(game.gettext("msg-dynamic-failure"))
			else 
				game.player.force.recipes["steel-axe3"].enabled = true
				game.player.print(game.gettext("msg-adv-steel-axe-2"))
				game.player.force.resetrecipes()
			end
		end
		--[[SAND]]--
		if game.player.force.recipes["basic-mining-drill-sand"].enabled then return
		elseif sand_counter > math.random(250,1000) then
			if math.random(1000)==1 then
				sand_counter = (sand_counter-math.random(500))
				game.player.print(game.gettext("msg-dynamic-failure"))
			else
				game.player.force.recipes["basic-mining-drill-sand"].enabled = true
				game.player.print(game.gettext("msg-sand-1"))
				game.player.force.resetrecipes()
			end
		end
		if game.player.force.recipes["sandwall"].enabled then return
		elseif sand_counter > math.random(2000,3500) then
			if math.random(5000)==1 then
				sand_counter = (sand_counter-math.random(500))
				game.player.print(game.gettext("msg-dynamic-failure"))
			else
				game.player.force.recipes["sandwall"].enabled = true
				game.player.print(game.gettext("msg-sand-2"))
				game.player.force.resetrecipes()
			end
		end
	end
	--[[Rewards for the Dynamic System]]--
	if event.tick%3600==0 then
		if game.player.force.technologies["steel-processing"].researched then return
		else
			if dytech_counter > math.random(25,250) then
				game.player.insert{name="steel-axe3",count=1}
				game.player.print(game.gettext("msg-reward-1"))
			end
		end
	end

Re: having trouble with counters xD

Posted: Sun Jan 12, 2014 12:46 am
by FreeER
Dysoch wrote:mmm odd, its appears its not the counter itself.
the error its gives is: attempted argument to compare number to nil (kinda weird error xD)
Ok, weird, I just copy/pasted in and it works fine...

Re: having trouble with counters xD

Posted: Sun Jan 12, 2014 12:50 am
by Dysoch
FreeER wrote:
Dysoch wrote:mmm odd, its appears its not the counter itself.
the error its gives is: attempted argument to compare number to nil (kinda weird error xD)
Ok, weird, I just copy/pasted in and it works fine...
maybe it has something to do with the core error i have on my pc? it is the core, and more specific the lualib, so it might be broken on my end xD

ill see tomorrow, there is something wrong with my pc. when i reboot, some things are disabled in the windows startup, and the next time, they are enabled. kinda starting to think i have a virus (seems unlikely, i have 2 virus scanners working tirelessly)

Re: having trouble with counters xD

Posted: Sun Jan 12, 2014 1:02 am
by FreeER
Dysoch wrote:kinda starting to think i have a virus (seems unlikely, i have 2 virus scanners working tirelessly)
No AV can identify everything (and I highly doubt any 5 can, at least not and still be able to actually run them and use the computer lol).

Re: having trouble with counters xD

Posted: Wed Jan 15, 2014 1:09 pm
by Dysoch
is there a way to set the counters in a table? i already tried with a glob, but that didnt work.
anyway i can insert it into a metatable? (i looked it up in lua-users wiki, but sadly i didnt understand it xD)

Re: having trouble with counters xD

Posted: Wed Jan 15, 2014 1:37 pm
by FreeER
Dysoch wrote:is there a way to set the counters in a table? i already tried with a glob, but that didnt work.
anyway i can insert it into a metatable? (i looked it up in lua-users wiki, but sadly i didnt understand it xD)
you could have glob.counters={gears=0, sand=0, ...} and then access/set those using glob.counters.gears=123 (or whatever)
as for metatables I haven't used them but from my understanding they are regular tables that when added as a 'meta table' get used whenever you ask for a non-existent index of the table and for 'object oriented' functions. so

Code: Select all

gears={}
mt={count=0, __index=function(t, k) return mt[k}}
setmetatable(gears, mt)
would allow you to ask for gears.count (even though it doesn't exist) and when you set gears.count it would create that index (and value) and stop using the metatable counters, you could also have

Code: Select all

gears={} 
mt={}
mt.__add = function (ta, tb)
  local sum=0
  for _, value in pairs(ta) do
    sum=sum+value
  end
  for _, value in pairs(tb) do
    sum=sum+value
  end
  return sum
end
setmetatable(gears, mt)
so that adding gears+sand (I think both both would need the metatable set to counters) would return the sum of all the values in both tables. At least I think so, like I said I haven't used them but I just looked at the Programming in Lua book/page

edit: youtube, says computer craft in title but I didn't see anything computer craft specific so.

Re: having trouble with counters xD

Posted: Wed Jan 15, 2014 7:08 pm
by Dysoch
YES YES YES YES YES YES YES (Because im Happy :P)

i finally got the counters to work with a glob, so they are saved when saving the game.
and i can still unlock items throu the ontick event!!!!!!

for those wanting to see it:
edit: this is taken from the script.dat in my testing savegame:

Code: Select all

counters={sand=0,gear=96,dytech=96,gears=0,mining=0,robot=0}
it is saved :P

Code: Select all

	glob.counters={dytech, gear, sand, mining, robot}
   
game.oninit(function()
	game.player.print(game.gettext("msg-welcome-1"))
	game.player.print(game.gettext("msg-welcome-2"))
	game.player.insert{name="wood",count=4}
glob.counters.gears=glob.counters.gears or 0
glob.counters.sand=glob.counters.sand or 0 
glob.counters.mining=glob.counters.mining or 0
glob.counters.robot=glob.counters.robot or 0
glob.counters.dytech=glob.counters.dytech or 0
glob.message=true
end)

--[[Dynamic System Counters increase]]--
game.onevent(defines.events.onplayercrafteditem, function(event)
	if event.itemstack.name=="stone-gear-wheel" or event.itemstack.name=="iron-gear-wheel" or event.itemstack.name=="steel-gear-wheel" then
		if glob.counters.gear == nil then glob.counters.gear=1
		else glob.counters.gear = glob.counters.gear + event.itemstack.count end
	end
	if event.itemstack.name=="wooden-axe" or event.itemstack.name=="iron-axe" or event.itemstack.name=="steel-axe" or event.itemstack.name=="steel-axe2" or event.itemstack.name=="steel-axe3" then
		if glob.counters.mining == nil then glob.counters.mining=1 
		else glob.counters.mining = glob.counters.mining + event.itemstack.count end
	end
	if event.itemstack.name=="repair-pack-0" or event.itemstack.name=="repair-pack" or event.itemstack.name=="repair-pack-2" then
		if glob.counters.gear == nil then glob.counters.gear=1
		else glob.counters.gear = glob.counters.gear + event.itemstack.count end
		if glob.counters.robot == nil then glob.counters.robot=1
		else glob.counters.robot = glob.counters.robot + event.itemstack.count end
	end
	if event.itemstack.name=="sandwall" then
		if glob.counters.sand == nil then glob.counters.sand=math.random(500)
		else glob.counters.sand = glob.counters.sand + math.random(500) end
	end
	if event.itemstack.name=="basic-mining-drill-sand" then
		if glob.counters.sand == nil then glob.counters.sand=math.random(500)
		else glob.counters.sand = glob.counters.sand + math.random(500) end
		if glob.counters.gear == nil then glob.counters.gear=25
		else glob.counters.gear = glob.counters.gear + 25 end
		if glob.counters.mining == nil then glob.counters.mining=2
		else glob.counters.mining = glob.counters.mining + 2 end
	end
	if event.itemstack.name=="basic-mining-drill" then
		if glob.counters.gear == nil then glob.counters.gear=5
		else glob.counters.gear = glob.counters.gear + 5 end
		if glob.counters.mining == nil then glob.counters.mining=5
		else glob.counters.mining = glob.counters.mining + 5 end
	end
end)

game.onevent(defines.events.onplayermineditem, function(event)
	if event.itemstack.name=="sand" then
		if glob.counters.sand == nil then glob.counters.sand=1
		else glob.counters.sand = glob.counters.sand + event.itemstack.count
		end
	end
end)

game.onevent(defines.events.ontick, function(event)
	if game.tick%60==0 then
		if glob.counters.gear == nil or glob.counters.sand == nil or glob.counters.mining == nil or glob.counters.robot == nil then 
		game.player.print(serpent.block(glob.counters.dytech))
		return else
			glob.counters.dytech = glob.counters.gear + glob.counters.sand + glob.counters.mining + glob.counters.robot
			game.player.print(serpent.block(glob.counters.dytech))
		end
	end
	--[[Dynamic System unlocks]]--
	if event.tick%60==0 then
		--[[REPAIR PACKS]]--
		if game.player.force.recipes["repair-pack"].enabled then return
		elseif glob.counters.robot > math.random(75,200) then
			if math.random(100)==2 then
				glob.counters.robot =(glob.counters.robot-math.random(50))
				game.player.print(game.gettext("msg-dynamic-failure"))
			else
				game.player.force.recipes["repair-pack"].enabled = true
				game.player.force.resetrecipes()
			end
		end
		if game.player.force.recipes["repair-pack-2"].enabled then return
		elseif glob.counters.robot > math.random(175,500) then
			if math.random(100)==2 then
				glob.counters.robot =(glob.counters.robot-math.random(glob.counters.robot/2))
				game.player.print(game.gettext("msg-dynamic-failure"))
			else
				game.player.force.recipes["repair-pack-2"].enabled = true
				game.player.force.resetrecipes()
			end
		end
		--[[GEARS]]--
		if game.player.force.recipes["iron-gear-wheel"].enabled then return
		elseif glob.counters.gear > math.random(75,200) then
			if math.random(1000)==1 then
				glob.counters.gear =(glob.counters.gear-math.random(25))
				game.player.print(game.gettext("msg-dynamic-failure"))
			else 
				game.player.force.recipes["iron-gear-wheel"].enabled = true
				game.player.print(game.gettext("msg-iron-gears"))
				game.player.force.resetrecipes()
			end
		end
		if game.player.force.recipes["steel-gear-wheel"].enabled then return
		elseif glob.counters.gear > math.random(750,1250) then
			if math.random(500)==1 then
				glob.counters.gear =(glob.counters.gear-math.random(100))
				game.player.print(game.gettext("msg-dynamic-failure"))
			else 
				if game.player.force.technologies["steel-processing"].researched then
					game.player.force.recipes["steel-gear-wheel"].enabled = true
					game.player.print(game.gettext("msg-steel-gears"))
					game.player.force.resetrecipes()
				else return
				end
			end
		end
		--[[AXES]]--
		if game.player.force.recipes["iron-axe"].enabled then return
		elseif glob.counters.mining > math.random(2,10) then
			if math.random(1000)==1 then
				glob.counters.mining =(glob.counters.mining-math.random(2))
				game.player.print(game.gettext("msg-dynamic-failure"))
			else 
				game.player.force.recipes["iron-axe"].enabled = true
				game.player.print(game.gettext("msg-iron-axe"))
				game.player.force.resetrecipes()
			end
		end
		if game.player.force.recipes["steel-axe"].enabled then return
		elseif glob.counters.mining > math.random(10,25) then
			if math.random(800)==1 then
				glob.counters.mining =(glob.counters.mining-math.random(4))
				game.player.print(game.gettext("msg-dynamic-failure"))
			else 
				if game.player.force.technologies["steel-processing"].researched then
					game.player.force.recipes["steel-axe"].enabled = true
					game.player.print(game.gettext("msg-steel-axe"))
					game.player.force.resetrecipes()
				else return
				end
			end
		end
		if game.player.force.recipes["steel-axe2"].enabled then return
		elseif glob.counters.mining > math.random(40,80) then
			if math.random(500)==1 then
				glob.counters.mining =(glob.counters.mining-math.random(10))
				game.player.print(game.gettext("msg-dynamic-failure"))
			else 
				game.player.force.recipes["steel-axe2"].enabled = true
				game.player.print(game.gettext("msg-adv-steel-axe"))
				game.player.force.resetrecipes()
			end
		end
		if game.player.force.recipes["steel-axe3"].enabled then return
		elseif glob.counters.mining > math.random(90,125) then
			if math.random(250)==1 then
				glob.counters.mining =(glob.counters.mining-math.random(50))
				game.player.print(game.gettext("msg-dynamic-failure"))
			else 
				game.player.force.recipes["steel-axe3"].enabled = true
				game.player.print(game.gettext("msg-adv-steel-axe-2"))
				game.player.force.resetrecipes()
			end
		end
		--[[SAND]]--
		if game.player.force.recipes["basic-mining-drill-sand"].enabled then return
		elseif glob.counters.sand > math.random(250,1000) then
			if math.random(1000)==1 then
				glob.counters.sand = (glob.counters.sand-math.random(500))
				game.player.print(game.gettext("msg-dynamic-failure"))
			else
				game.player.force.recipes["basic-mining-drill-sand"].enabled = true
				game.player.print(game.gettext("msg-sand-1"))
				game.player.force.resetrecipes()
			end
		end
		if game.player.force.recipes["sandwall"].enabled then return
		elseif glob.counters.sand > math.random(2000,3500) then
			if math.random(5000)==1 then
				glob.counters.sand = (glob.counters.sand-math.random(500))
				game.player.print(game.gettext("msg-dynamic-failure"))
			else
				game.player.force.recipes["sandwall"].enabled = true
				game.player.print(game.gettext("msg-sand-2"))
				game.player.force.resetrecipes()
			end
		end
	end
	--[[Rewards for the Dynamic System]]--
	if event.tick%3600==0 then
		if game.player.force.technologies["steel-processing"].researched then return
		else
			if glob.counters.dytech > math.random(25,250) then
				game.player.insert{name="steel-axe3",count=1}
				game.player.print(game.gettext("msg-reward-1"))
			end
		end
	end
i am even considering to delete the if glob.counters.#NAME# == nil lines because they are no longer needed :P