Assigning Variables

Started by ThalliumShine, February 12, 2014, 06:20:56 am

Previous topic - Next topic

ThalliumShine

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.

KK20

February 12, 2014, 11:29:11 am #1 Last Edit: February 13, 2014, 11:23:13 am by KK20
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.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

Heretic86

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...
Current Scripts:
Heretic's Moving Platforms

Current Demos:
Collection of Art and 100% Compatible Scripts

(Script Demos are all still available in the Collection link above.  I lost some individual demos due to a server crash.)

LiTTleDRAgo

Quote from: KK20 on February 12, 2014, 11:29:11 am
    @level |= case @id


this will throws an error, it should be "||="

KK20

Fixed. My memory sometimes fails me.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

ThalliumShine

Hi again. I'll be trying the script. I was out for a while and I noticed I got help quickly. Thanks!