What is attr_accessor and what does it do?
I'm sorry if it's obvious but I'm not sure what it does, I have used it in a script I was following from a tutorial however he does not go into it, he mearly skims it.
The most I can assume is that it is kind of like setting and label and using goto label.
So, for example, I have a very very incomplete script and I am looking to go into
Class Update_NPCNeeds
and have it update every 60 frames, would attr_accessor help with that?
Warning: Longish code
class NPC_NeedsInitialize < Scene_Base # Create a scene so Game_Interpreter Works
def initialize # Initialize content
@mapid = [] #Map ID Array (to check for existing maps in D😎
@npcid = [] #NPC ID Array (to check for existing NPCs in D😎
@npcinitialized = [] # NPC Initialized (Probably unneeded)
@npcmoney = [] #NPC Money it sets up an NPCs money that it will drop on death (maybe)
@npcs = 0 #The amount of NPCs in the array
@maps = 0 #The amount of maps in the array
#Captain hindsite said I should have used array.length
@npchunger = []
@npcthirst = []
@npcsleep = []
end
def prepare(npcid, mapid, npcmoney) # Get info from event script (user entered)
for i in 1...@maps #Check all maps, if one doesn't exist, add it.
if @mapid == mapid
@currentmapused = i
end
if mapid != @mapid && i == @maps
@mapid.insert(i, mapid)
@currentmapused = i
end
end
a = @currentmapused*1000
for i in 1...@npcs #Check all NPCs, if one doesn't exist, add it.
b = a+i
if @npcid == npcid && i == @npcs
@currentnpcused = i
end
if npcid != @npcid && i == @npcs
@npcid.insert(b, npcid)
@currentnpcused = b
end
end #By the end of this, all npc id's should be like this:
#(MapID * 1000) + NPCID So there's room for 999 NPCs
#Example: MapID = 1 NPCID = 20 So his/her ID would be 1020
end
end
class Update_NPCNeeds
def npcupdate
#Placeholder values
@currentnpcused = a
@currentmapused = b
c = b*1000
d = a+c
#NPC Hunger
if @npchunger[d] == nil
@npchunger.insert(d, 100)
end else
if @npchunger[d] >= 0
e = @npchunger[d] - 1
@npchunger.insert(d, e)
end
#NPC Thirst
if @npcthirst[d] == nil
@npcthirst.insert(d, 100)
end else
if @npcthirst >= 0
e = @npchunger[d] - 1
@npchunger.insert(d, e)
end
#NPC Sleep
if @npcsleep[d] == nil
@npcsleep.insert(d, 100)
end else
if @npcsleep >= 0
e = @npcsleep[d] - 1
@npcsleep.insert(d, e)
end
end
end
class Game_Interpreter
def npcneeds(npcid, mapid, npcmoney)
SceneManager.call(Scene_DataHolder)
SceneManager.scene.prepare(npcid, mapid, npcmoney)
end
end
And no, I don't want someone to make anything for me.
I just want to know how to use attr_accessor and if you are a very nice person (which you are, that's why I luv you 🙂) share how I would run this every 60 frames on every NPC tagged <human> or <orc>
I can probably figure out the tagging thing, I think @Yanfly has a tutorial on that or something.
Anyway thanks! It's another late late night so I need to sleeeeeeepppppp.
I'm sorry if it's obvious but I'm not sure what it does, I have used it in a script I was following from a tutorial however he does not go into it, he mearly skims it.
The most I can assume is that it is kind of like setting and label and using goto label.
So, for example, I have a very very incomplete script and I am looking to go into
Class Update_NPCNeeds
and have it update every 60 frames, would attr_accessor help with that?
Warning: Longish code
class NPC_NeedsInitialize < Scene_Base # Create a scene so Game_Interpreter Works
def initialize # Initialize content
@mapid = [] #Map ID Array (to check for existing maps in D😎
@npcid = [] #NPC ID Array (to check for existing NPCs in D😎
@npcinitialized = [] # NPC Initialized (Probably unneeded)
@npcmoney = [] #NPC Money it sets up an NPCs money that it will drop on death (maybe)
@npcs = 0 #The amount of NPCs in the array
@maps = 0 #The amount of maps in the array
#Captain hindsite said I should have used array.length
@npchunger = []
@npcthirst = []
@npcsleep = []
end
def prepare(npcid, mapid, npcmoney) # Get info from event script (user entered)
for i in 1...@maps #Check all maps, if one doesn't exist, add it.
if @mapid == mapid
@currentmapused = i
end
if mapid != @mapid && i == @maps
@mapid.insert(i, mapid)
@currentmapused = i
end
end
a = @currentmapused*1000
for i in 1...@npcs #Check all NPCs, if one doesn't exist, add it.
b = a+i
if @npcid == npcid && i == @npcs
@currentnpcused = i
end
if npcid != @npcid && i == @npcs
@npcid.insert(b, npcid)
@currentnpcused = b
end
end #By the end of this, all npc id's should be like this:
#(MapID * 1000) + NPCID So there's room for 999 NPCs
#Example: MapID = 1 NPCID = 20 So his/her ID would be 1020
end
end
class Update_NPCNeeds
def npcupdate
#Placeholder values
@currentnpcused = a
@currentmapused = b
c = b*1000
d = a+c
#NPC Hunger
if @npchunger[d] == nil
@npchunger.insert(d, 100)
end else
if @npchunger[d] >= 0
e = @npchunger[d] - 1
@npchunger.insert(d, e)
end
#NPC Thirst
if @npcthirst[d] == nil
@npcthirst.insert(d, 100)
end else
if @npcthirst >= 0
e = @npchunger[d] - 1
@npchunger.insert(d, e)
end
#NPC Sleep
if @npcsleep[d] == nil
@npcsleep.insert(d, 100)
end else
if @npcsleep >= 0
e = @npcsleep[d] - 1
@npcsleep.insert(d, e)
end
end
end
class Game_Interpreter
def npcneeds(npcid, mapid, npcmoney)
SceneManager.call(Scene_DataHolder)
SceneManager.scene.prepare(npcid, mapid, npcmoney)
end
end
And no, I don't want someone to make anything for me.
I just want to know how to use attr_accessor and if you are a very nice person (which you are, that's why I luv you 🙂) share how I would run this every 60 frames on every NPC tagged <human> or <orc>
I can probably figure out the tagging thing, I think @Yanfly has a tutorial on that or something.
Anyway thanks! It's another late late night so I need to sleeeeeeepppppp.