Firgof Umbra
Member
I'm pretty green behind the ears when it comes to coding, so I came across a problem when I was working on this little side project of mine. What I want to occur here is for an array to be created when the game starts up and for there to be creatable objects called Squads which have an ID so that I can do "Squad[1].str = 50" for instance.
The problem is that I'm not quite sure how to accomplish that. I've got Squads creating now with their stats being properly initialized as far as I can tell but (as I'm sure you'll see) I'm not sure how to start as I'm very unfamiliar with Arrays. I assumed I might accomplish it by doing a for loop (checking to see if an index in the array was empty and, if it was, assigning the Squad to that number) but I wasn't sure how to do that properly here.
The end result I'm trying to achieve here with this snippet is being able to do Squad.new and the Class creating a new Squad and assigning it to a free ID slot; the intention being the first created Squad will be Squad[1], the second being Squad[2], etc. but I'm not sure how many Squads the player might have so I'd like to keep it more open than my initial Array creation implies.
So: What do you suggest, HBGames?
The problem is that I'm not quite sure how to accomplish that. I've got Squads creating now with their stats being properly initialized as far as I can tell but (as I'm sure you'll see) I'm not sure how to start as I'm very unfamiliar with Arrays. I assumed I might accomplish it by doing a for loop (checking to see if an index in the array was empty and, if it was, assigning the Squad to that number) but I wasn't sure how to do that properly here.
The end result I'm trying to achieve here with this snippet is being able to do Squad.new and the Class creating a new Squad and assigning it to a free ID slot; the intention being the first created Squad will be Squad[1], the second being Squad[2], etc. but I'm not sure how many Squads the player might have so I'd like to keep it more open than my initial Array creation implies.
So: What do you suggest, HBGames?
Code:
class GameStart
SQUAD_ID = [nil, nil, nil, nil]
print "Created 4 Squads"
end
class Squad
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :STATUS # Squad Status
attr_reader :ID # Squad Number
attr_accessor :MORALE # Squad Morale
attr_accessor :HP # Squad Health
attr_accessor :ATK # Squad ATK Value
attr_accessor :DEF # Squad DEF Value
attr_accessor :AGI # Squad AGI Value
attr_accessor :STR # Squad Strength
attr_accessor :CRITFAIL # Squad has Critically Failed
attr_accessor :CRITSUCCESS # Squad has Critically Succeeded
attr_accessor :ASSIGNED # Squad has been Assigned to a Task
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
# Squad Status
@ID = []
@STATUS = []
# Unit Stats
@MORALE = 0
@HP = 0
@STR = 0
# Combat Stuff
@ATK = 0
@DEF = 0
@AGI = 0
# Task Assignment Stuff
@CRITFAIL = false
@CRITSUCCESS = false
@ASSIGNED = false
print "Squad Created Succesfully"
end
#--------------------------------------------------------------------------
# * Get Squad ID (ID)
#--------------------------------------------------------------------------
def ID
@ID = $SQUAD_ID
print self.index
return [self.index]
end