Increasing gap betwen levels — Gideros Forum

#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# Increasing gap betwen levels

Member
I've been trying (and failing) to create a function that spits out a level structure of "hub levels" and "levels". The higher the level, the more levels should go between hubs;
 Level 1 (hub) Level 2 Level 3 Level 4 (hub) Level 5 Level 6 Level 7 Level 8 (hub) Level 9 Level 10 Level 11 Level 12 Level 13 (hub) Level 14 Level 15 Level 16 Level 17 Level 18 Level 19 (hub)
Can anyone help me figure this one out?
My Gideros games: www.totebo.com

• Member
Ideally something like getLevels( total_levels, levels_between_first_and_second_hub, level_increase_per_hub ).
My Gideros games: www.totebo.com
• Maintainer
I must have misunderstood what you are after since it sounds simple to me:
 local function getLevels( total_levels, levels_between_first_and_second_hub, level_increase_per_hub) local nexthub=levels_between_first_and_second_hub local level=1 local levels={} local function makeLevel(isHub) if isHub then print("Level "..level.." (hub)") else print("Level "..level) end level=level+1 total_levels=total_levels-1 table.insert(levels,{levelNum=level,hub=isHub}) end --First level is a hub makeLevel(true) --Generate subsequent levels while total_levels>0 do if nexthub==0 then levels_between_first_and_second_hub=levels_between_first_and_second_hub+level_increase_per_hub nexthub=levels_between_first_and_second_hub makeLevel(true) else nexthub=nexthub-1 makeLevel(false) end end return levels end   getLevels(19,2,1)
• Member
I'll try this out in the morning, but it looks fantastic. Remember, "simple" is relative.
My Gideros games: www.totebo.com
• Member
Maybe something like this might work?
 Levels = Core.class()   function Levels:init() self.betweenCount = 0 self.hubCountDown = 0 end   function Levels:makeLevel() local hubCountDown = self.hubCountDown - 1 if hubCountDown < 0 then local betweenCount = self.betweenCount + 1 -- increment gap between levels and hubs hubCountDown = betweenCount -- start counting down again -- generate hub else -- generate level end self.hubCountDown = hubCountDown end

Likes: totebo

+1 -1 (+1 / -0 )Share on Facebook
• Member
Use Fibonacci number as Hub, Why not? (Just for kidding)

Likes: SinisterSoft

Coming soon
+1 -1 (+1 / -0 )Share on Facebook
• Member
Beautiful, thanks guys. I went with @hgy29's one, works a charm! I can work out most things, but that one had me stumped for some reason.

Likes: antix

My Gideros games: www.totebo.com
+1 -1 (+1 / -0 )Share on Facebook
• Member
Most often it's the little things that make you brain freeze