ID:818588
 
(See the best response by DarkCampainger.)
Code:
mob/verb/RemoveSkills()
var/Remove=src.ShowSkills[1]
var/Add=Lists[ShowSkills.len+1]
src.ShowSkills+=Add
src.ShowSkills-=Remove

src.ShowSkill()
mob/verb/ShowSkill()
for(var/V in src.ShowSkills)
src<<V
mob/proc/ShowSkills()
for(var/V=1,V<=5,V++)
ShowSkills+="Number [V]"
var/list/Lists=list("")
mob/var/list/ShowSkills=list()
proc/PopulateLists()
for(var/V=1,V<=20,V++)
Lists+="Number [V]"


Problem description:This code was only made to test but i want to know that i am making a system which only show 6 skills on HUD and when user gets to 6th skill the first one dis appear and another one is added on the list but cant figure out.
something like this
|---|7//In the list
^ //More Skill arrow- When press this no 1 disappear and no 7 will be added to the list then all of them moves down so it only shows 6 skills.
|---|6
|---|5
|---|4
|---|3
|---|2
|---|1


try something like this its just a little example.
mob/var/snumber
//then where it adds skill to the hud do
if(snumber>6)
//minus one of the skills
Best response
You can use a for() loop pretty easily to loop through only a subset of your master skills list.

Basically, you'll need a constant or define containing the number of skills that are visible at once. And you'll need a variable for your player which holds their current index in the skills list. Then you just have to do some bounds checking, and run through the valid indexes from their current index to 'n' beyond that.

#define SKILL_VISIBLE_COUNT 6

mob/Player
var/skillVisibleIndex = 1

proc/DisplaySkills()
// Do some bounds checking to make sure we stay within the list
skillVisibleIndex = max(1, min(skillVisibleIndex, skills.len - SKILL_VISIBLE_COUNT + 1))

// Calculate our ending index (make sure it stays within length of skills)
var/endIndex = min(skillVisibleIndex + SKILL_VISIBLE_COUNT - 1, skills.len)

// Loop through a subset of the skills list
for(var/index = skillVisibleIndex to endIndex)
src << "Skill [index]: [skills[i]]"


When incrementing or decrementing the skillVisibleIndex, don't forget to do similar bounds checking.