[Ruby] Registering game over in CMD

L.W. Flouisa

NumeroHex
Veteran
Joined
Mar 31, 2012
Messages
198
Reaction score
48
First Language
English
Primarily Uses
RMMV
I'll word it differently.

How do you keep ruby from over ruling an if/else statement if the variables falls below the requirement? And do if/else statement go above or below a when statement?
 
Last edited by a moderator:

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,604
Reaction score
1,959
First Language
English
Primarily Uses
RMMV
I'm not 100% sure what you mean, but I'll do my best to answer:

If/else statements are interpreted in the order they're written. If one condition returns true, all the ones below it will be ignored and whatever code is in the branch for the one that was true will be executed.

If/else and when are two different things: when is used in a case statement, which is like a shorthand if. They're not related.
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,365
Reaction score
7,674
First Language
German
Primarily Uses
RMMV
How do you keep ruby from over ruling an if/else statement if the variables falls below the requirement? And do if/else statement go above or below a when statement?
You're one step too far in your thinking. If/Then does not have a range or relative requirement, it is only concerned with whether a statement is true or false.

What you're probably talking about is when a statement is true for several option, like a statement of x<10 that is true for a lot of numbers.

There are a lot of ways to order logic statements - but that has to do with logic ordering, NOT with the if command.

1) make the statement check a range (x>7&&x<10)

2) order several if checks depending on the statement (if you're checking for lower than, start with the smallest limit - if you're checking for greater than, start with the greatest limit and so on)

3) use a case structure

But really, it depends on the logic structure - and therefore it's different for different statements and there can't be a general answer.
 

L.W. Flouisa

NumeroHex
Veteran
Joined
Mar 31, 2012
Messages
198
Reaction score
48
First Language
English
Primarily Uses
RMMV
I'll be sure to look up some logic statements then.

Oh the HP variable seems to restart every time I reload the same script. I ended up doing this as a way of combating an odd problem I've been having, where the if/else statement is skipped altogether.

Functionally what I mean is, that after the initial if/else statement is written:

if hp == 0

  load 'Game Over.rb'

elsif hp >= 1

  puts 'Your cruiser is still kicking.'

end

Because the script would otherwise only run once, I did a load command. But this ended up restarting the code altogether, and resetting the variable.

Is there a way to continuously check without restarting the variable by reloading the script?

Wanting to get this portion right before I move onto checking for ehp (the enemy fortress.)
 
Last edited by a moderator:

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,365
Reaction score
7,674
First Language
German
Primarily Uses
RMMV
What you're talking about is probably a loop - and you can't use an exclusive loop because that would halt all other code.

So what you'll need to do for a repeating check is to identify an existing loop (most probably one of the update- or refresh-methods) that repeats as often as you want, and then add your command there.

It'll be a lot easier to do with eventing (because the parallel processes are automatically connected to the correct update method) then with pure scripting (where you have to identify the correct update yourself).

So the question is: what do you want to check when? There are a dozen different update methods, that are being called at different parts of the game loop, and no one can select the correct update function without knowing when and how often the sequence needs to be checked.

No, "as often as possible" is the wrong answer, because that will create too much lag.

The ideal answer is "as often as neccessary and as few times as possible" - that's why it isn't easy to identify the correct place for the loop to be entered.
 

L.W. Flouisa

NumeroHex
Veteran
Joined
Mar 31, 2012
Messages
198
Reaction score
48
First Language
English
Primarily Uses
RMMV
Oh no I'm not referring to script, I'm referring to pure ruby. Is that confusion?

I'm wanting to check for if hp is less than zero in pure ruby. So when I finally get around to RGSS3 I'll have ruby scripting under my nose.

I'm wanting the system to recheck if hp is equal to or less than zero, to prompt load game over.

Edit: Note the dice is for a damage multiplier I'm using later on.
 
Last edited by a moderator:

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,365
Reaction score
7,674
First Language
German
Primarily Uses
RMMV
RGSSx are all variants of Ruby, and scripting in RM is the same as programming in Ruby.

An dyou don't need to load scripts in RGSS, they are all in the script editor and can be called directly.

Or what are you trying to do with that "Load game over"?
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,862
Messages
1,017,047
Members
137,569
Latest member
Shtelsky
Top