Chaos Project

RPG Maker => RPG Maker Scripts => Script Troubleshooting => Topic started by: ThalliumShine on February 12, 2014, 06:20:56 am

Title: Assigning Variables
Post by: ThalliumShine on February 12, 2014, 06:20:56 am
Hello again. So I've started to script, thanks to the tutorials I have in my drive. Got them working just today. I have a question about assigning variables. Basically, what I want is...

I want to assign an enemy a simple level number. For example, a Basilisk is assigned a variable level 2. So to go on, for example:

Skeleton - assigned a variable named enemy level with the value of 1
Basilisk - assigned a variable named enemy level with the value of 2

How can I get this done? I made this on Game_Battler where I assigned it to an attribute accessor but I have no idea after that.
Title: Re: Assigning Variables
Post by: KK20 on February 12, 2014, 11:29:11 am
I would probably do something like this

class RPG::Enemy

 def level
   @level ||= case @id
     when 1 then 1
     when 2 then 1
     when 3 then 2
     when 4..10 then 3 # enemies of id 4 through 10
     # and so on
   end
   return @level
 end

end

class Game_Enemy < Game_Battler

 def enemy_level
   return $data_enemies[@enemy_id].level
 end

end

Can be pasted anywhere above Main. Untested--solely going off intuition here.
Title: Re: Assigning Variables
Post by: Heretic86 on February 12, 2014, 05:49:46 pm
How are the enemies being given that Level?  In the Name of the Enemy itself, or Battle Script from Troops?

Name: Ghost[level=1]
Battle: $game_troop.enemies[0].level = 1

Just curious...
Title: Re: Assigning Variables
Post by: LiTTleDRAgo on February 13, 2014, 04:34:48 am
Quote from: KK20 on February 12, 2014, 11:29:11 am
    @level |= case @id


this will throws an error, it should be "||="
Title: Re: Assigning Variables
Post by: KK20 on February 13, 2014, 11:24:10 am
Fixed. My memory sometimes fails me.
Title: Re: Assigning Variables
Post by: ThalliumShine on February 13, 2014, 04:54:14 pm
Hi again. I'll be trying the script. I was out for a while and I noticed I got help quickly. Thanks!