Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

How do I make a script recognize that i want a value to be 1-10 for example?

I want my script *Minkoff* to recognized that i want battlers 1-30 just to throw out a number to be default battlers. how do I tell script that I want more than 1 number such as 1-30?
 
If i under stan you want random battelers, yes?

Code:
    @sprite.bitmap = RPG::Cache.title("battler_Name"+(rand(30)+1).to_s)
I think that should work.
Where you put it I don't know.
 
No I want the script to recognized that numbers 1-30 have the same conditions. So if i choose 1-30 to be special they are all special but 40-50 are not special... understand?
 
Code:
#==========================================================================
  #   ****                    GENERAL CONTROLS                       ****   #
  #==========================================================================

  # * Default Battler Style Switches
  #--------------------------------------------------------------------------        
  DEFAULT_ENEMY           = true   # If true, these switches allows the use
  DEFAULT_ACTOR           = false   # of default battlers for actors/enemies
  DEFAULT_ENEMY_ID        = []      # Ids of enemies using default battlers
  DEFAULT_ACTOR_ID        = []     # Ids of actors using default battlers
  DEFAULT_COLLAPSE_ACTOR  = false   # If true, restores the old 'red fade'
  DEFAULT_COLLAPSE_ENEMY  = false   #   collapse effect (using spritesheets)

I want Default enemy ID to some how say [monster 1 through 30 are default battlers] I could place a comma between every number but that would be time consuming and messy.
 

khmp

Sponsor

It looks like you're creating a constant and I don't think that it can be altered outside the declaration. However if you could because it's array. You could use DEFAULT_ENEMY_ID.push(number you want added). Stick it in a loop

Code:
for i in 0..30
  DEFAULT_ENEMY_ID.push(i)
end

Or if you want random values which are unique.
Code:
taken_ids = []
for i in 0..30

  # Loop to keep generating values till a unique is found.
  loop do
    rand_id = rand(30) # Generate an id 0-29

    # Walk through the taken ids comparing random value. 
    for j in 0..taken_ids.size -1

      # Make sure the id is not already taken.
      if rand_id == taken[j]
        next # Repeat loop to generate another value.
      end

    end

    # Add the unique id to our taken id array.
    taken_ids.push(rand_id)
  end
  DEFAULT_ENEMY_ID.push(taken_ids[i])
end

But I'm still lost on what you are attempting :-/

Good luck with it in any case! :thumb:
 
shinzo123;294984 said:
I want my script *Minkoff* to recognized that i want battlers 1-30 just to throw out a number to be default battlers. how do I tell script that I want more than 1 number such as 1-30?

Ruby has a variable type called a Range which sounds like exactly what you're looking for. Here's some examples of how to use it:

Code:
DEFAULT_ENEMY_ID        = 1..30      # Ids of enemies using default battlers

# See if an enemy's id is within the default range:
my_enemy_id = 86
DEFAULT_ENEMY_ID.include?(enemy_id) # false

# Get the minimum and maximum value in the default range:
min = DEFAULT_ENEMY_ID.first
max = DEFAULT_ENEMY_ID.last

# Convert it to an array
DEFAULT_ENEMY_ID.to_a # [1, 2, 3, 4, 5, 6, ... 28, 29, 30]

If you want to know more about the Range class, you can check out the docs for it: http://www.ruby-doc.org/core/classes/Range.html
 

khmp

Sponsor

[original_post]Ranges don't seem to work in RGSS. :( Shame too, I thought you just shortened some of my incremental array code.[/original_post]

Ranges work in RGSS. :) They help to shorten the code for incremental arrays.
 

khmp

Sponsor

I tried to use it and got a syntax error. What am I doing wrong because as I said it would greatly shorten some of my array code? I just tried something simple like 'Range = 0..5'. Does the syntax change in RGSS?

Never, never name a variable the same as the type you are trying to create.
 
Nothing changes in rmxp. All RGSS is an expansion of the Ruby Library (just like the MACL).

It all depends on what is reading the object, as Ranges themselves are objects. If you try to use an array method on a range object, then yes, you will get an error in the array method isn't in the Range object class. All you really have to do is use range.to_a it will change your range to an array.

If you didn't get what you wanted out of me, show me exactly what you are trying to do, as the above codes just confuse the hell out of me.
 

khmp

Sponsor

I am a complete idiot. I named my variable the same as the type. So when I wrote the line "Range = 0..5" it gave a syntax error. It works otherwise so I will edit my previous post to avoid confusion of people coming to this topic. Sorry SephirothSpawn.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top