Ruby/RGSSx questions that don't deserve their own thread

Hey, easy questions here.

My game isn't going to be linear, with a story I mean. Also there will be many characters with many stages, here's what I mean:

a - Character 1 will not know you until you first talk to him *turn switch 1 on*

b - When switch 1 on, talking to him again will do something like "Oh, hi again, how you doing?, "blah blah", <do something> *turn switch 2 on*, "I can be your companion now" *turn switch 3 on"

c - When the character is in party *turn switch 4 on* (because other character may trigger special events if some character is in party)

So each character will take 3, 4 or 5 switches (min) and there's also many other things I will be using with multiple switches, common events, self switches.

My questions are (excluding anything related to "parallel process", not talking about that):

1) Is my game going to have Lag/FPS drops if it has self switches in every map, 400+ total switches and 30+ common events?

2) Is it ok if I have switches grouped like 1-20 for something 100-200 for some other thing, and I skip 10 or 20 switches without using them just to be like separators? Or will that lag save/load times?
FPS drop can only be caused by parallel process events if we are talking about eventing only.


So, no, you won't have any FPS drop just by using that many switches.


If you don't mind to waste 10-20 switches for separators, than you are safe to do that as well.
Hello. I've run into a problem while testing an event. I want the player to be able to store negative numbers within a variable. The default input is a no-go here, so I opted to use a text input instead. It's similar to the renaming feature, except it stores the value into a variable. The issue isn't with the script, so I won't bother linking to it.

Here's the issue: I have a conditional branch that checks for the number -23. I want the player to be able to type "-" in front of (anywhere) a number to return a negative value. So I tried adding this bit of code after the variable was set.

x = $game_variables[1]if x.include?("-")x.tr!("-","") ; x.to_i ; x *= -1else x.tr!("-","") ; x.to_i ; end$game_variables[1] = xBut I'm getting a " 'eval' Negative Argument" error. Is there a another way to do this?

Edit: On second thought, the script could easily be the problem... http://www.rpgmakervxace.net/topic/4238-simple-text-input/

After testing it again with regular numbers, I didn't get any errors, but the conditional branch still couldn't recognize the value.

Edit: I'll write something more specific later, but I got this to work...

Previous:

def on_input_ok $game_variables[@var] = @edit_window.name return_scene endNew:

Code:
  def on_input_ok    if @edit_window.name.to_i > 0 or @edit_window.name.include?("-")      $game_variables[@var] = @edit_window.name.to_i    else      $game_variables[@var] = @edit_window.name.to_s    end    return_scene  end
Hey, easy questions here.


My game isn't going to be linear, with a story I mean. Also there will be many characters with many stages, here's what I mean:


a - Character 1 will not know you until you first talk to him *turn switch 1 on*


b - When switch 1 on, talking to him again will do something like "Oh, hi again, how you doing?, "blah blah", <do something> *turn switch 2 on*, "I can be your companion now" *turn switch 3 on"


c - When the character is in party *turn switch 4 on* (because other character may trigger special events if some character is in party)


So each character will take 3, 4 or 5 switches (min) and there's also many other things I will be using with multiple switches, common events, self switches.


My questions are (excluding anything related to "parallel process", not talking about that):


1) Is my game going to have Lag/FPS drops if it has self switches in every map, 400+ total switches and 30+ common events?


2) Is it ok if I have switches grouped like 1-20 for something 100-200 for some other thing, and I skip 10 or 20 switches without using them just to be like separators? Or will that lag save/load times?
This has nothing to do with scripting. What you are doing is eventing. Hit F11 and you'll see what scripting looks like. Please ask for information on this in the VX Ace Support forum. Thank you.
I feel so stupid for posting so many questions here. =P

How can I move variable to another class?

For example

Spoiler
class Warrior < Sorcerer def init_variables @turtle = 0 # so I have that variable here and the stuff is happening with this... end def smell_da_turtle something here IDK, for example if smell_da_turtle @turtle += 1 # here... else lol end endendclass Windows_XP < Window_Base (...) def refresh contents.clear draw_text(0, 0, 100, 24, @turtle) #I want to do something like this end (...)end
Thank you in advance.
@turtle is a variable in a different class. You don't want to MOVE it - you just want to reference it.


What is the instance of your Warrior class called? @turtle doesn't exist unless you do something = Warrior.new


Then if something is accessible by your window class, you'd just do something.turtle


This would require attr_reader: turtle at the top of your Warrior class as well.


Just look at the way the default scripts do it.
Yeah, I wanted just to reference it.

(Just show the value of the local variable from another class)

I have a minigame script, where there are few local variables like score and such and I wanted to show that information in that window. 

Hmm.. I'm not sure ... I think I'll create a new thread for that to not spam here anymore.

Thanks for replying.

> CONTINUE

> EXIT GAME
@variables are instance variables not local variables...
@variables are instance variables not local variables...
What a shame. =P Thanks for clarifying. (=
How can I put 'wait' command in scripts?

I tried putting 'wait(500)', but game exploded...
Where are you putting it?  Show us.

Wait is a command that's known by Game_Interpreter and Game_Character.  If you're putting it somewhere else, look to see how Game_Interpreter does it, and do something similar.  Keep in mind it may also call other methods in Game_Interpreter.
Well...

For example player is doing something (clicking something (command etc.)), that plays SE, fadeouts BGM, then plays another one - so for example I have this:

#there are classes and defs, but it's not important #actions below are forced, when player does something if playerdoessomething some SE.play      RPG::BGM.fade(500)      500.times { Graphics.update } #also tried this, but it freezes (pauses) the whole game, I just want to make a pause in processing of these actions      some BGM.play #(...)I want to fadeout BGM and put a wait command to let the fadeout finish before playing another one.

I'm not sure how to explain this. =P

If that's important where exactly I want to put this, then I can provide a part of that script, though I thought it'd be something more common and easier. xD
Well, Kernel.sleep (or just 'sleep') is the way of stopping things.

But, it happened to me that

puts "A"sleep(1)puts "B"Outputs:<wait 1 second>

"A"

"B"

Instead of :

"A"

<wait 1 second>

"B"

(Actually, the only language I know of which has a non-buggy sleep method is Python...)

Or I think you can use Graphics.wait (or Graphics.sleep? I forgot...) but it does the same as Kernel.sleep.

In which context are you putting those?

Is it like for playing BGM for when earning an achievment?

Maybe try some alternative?
"Graphics.wait" is actually very close to what i'm looking for, but it pauses the whole game, while I just want to stop processing of these actions.

I'm editing a minigame, where I need to implement sort of an event, but everything is done in a Scene, that's not the Scene_Map.

So.. I can't use eventing ~ I have to do these via scripting.

If player is picking up a powerup - a list of commands is forced and that's where I want to put stuff in.

Sure I can live without that wait and make the BGM change instantly, along with other stuff, but I simply wanted to make it more 'smooth'.

It's like a parallel process - player is doing something - a list of commands is processing in background.

So... It's like putting wait command in parallel event, but in scripts.

"Graphics.wait" works, but it pauses the whole game (like autorun event) -  what I'm looking for is to pause like a wait command in parallel event.

What a shame there's no simple way to do such a obvious thing...
Hmmm... maybe you want a Thread?

Thread is an object that allows asynchronous command executions.

You can implement it something like :

def when_event_happens Thread.new{ # Do something sleep(number_of_seconds) # Do something }endIn this case, sleep won't effect the main thread, that means, the game won't stop, but BGM will play.For more informations about Threads you can see Ruby library documentation.

Also, if you are interested in what threading means, you can google it, there are lots of explainations about it.
Hmmm... that works as I want...

As long as there's no bad things in using threads, then this solution is okay. *I goggled it, but there's lots of stuff*

The only thing is - the wait command also affects the beginning, for example I have:

Thread.new{  #BGM fadeout sleep(10) #Change background or something sleep(1) #play another BGMand it looks like this

#doing the thing and forcing thread to run #---the thread--- waiting 10 seconds #Why is that? BGM fadeouts waiting 10 seconds background changed waiting 1 second another BGM starts to play #---end---
WtvmtpT.png


OR the solution could be putting multiple threads, for example:

*picking up power up*PLAY SEFadeout BGMThread.new{sleep(4)do something else in the middle}Thread.new{sleep(1)PLAY ANOTHER BGM}###############Can I do that without any consequences etc.?

WtvmtpT.png


I did that:

*player did something* SOME SE.play RPG::BGM.fade(500) Thread.new{ sleep(1) ANOTHER BGM.play }and noticed weird behavior - I had to wait ~4 seconds, but what is worse - I had to wait even more upon launching that thread second time.

---<@EDIT> Or actually it did work after more tests... that's weird </@EDIT>---

*lol I can't believe there's no such a common and obvious thing ~ this is ridiculous... Anyway, I'll try to do something or just make everything 'instant'.*

I'll try to use instance variables for that and hope it will work.
Then try something like this:

First, for the test insert this code in any script slot you want :

a = 0Thread.new{loop{ a += 1 puts a}}Look at the console.Numbers will be logged constantly, and you can count how many seconds do you want the thread to wait and then convert them to Thread ticks with this test.

Now, the main code :

Code:
def when_something_happens  @a = 0  Thread.new{    @a += 1    if @a == the_amount_of_thread_ticks_to_wait      # Do what you want      break    end  }end
Do you understand?
I understand the main concept of this. ~

The first code isn't needed? ~that was only for test?

Um... I've put that:

@a = 0 Thread.new{loop{ @a += 1 if @a == 1000 #stuff here break end }}but that didn't worked well ~ there was a tiny pause though, but changing the number doesn't do anything.

If I understand correctly - firstly it sets @a to 0, then enters the loop, where it raises @a by 1 each frame and does the thing if the @a reaches the value I've put in and breaks loop right?

And by the way, putting:

Thread.new{sleep(1)#stuff}worked as intended, but the wait time varies - once it'll be one second ~ another time two seconds ~ so it's not that bad I guess.
Just make a new variable in the scene, name it however you like. That will be your counter.

In the update method, increment it by 1 (or decrease, depends on your conditions for triggering the stuffs).

And just use that variable for timing your other stuffs happening. When the counter reaches XY value, do this, reset the timer, when it reaches XY value again, do this and that, etc.

Basically, this way you have your own timer on the scene.

Meddling with Threads is not something I would do for a simple timing logic.

Btw, this:

Spoiler
def when_something_happens @a = 0 Thread.new{ @a += 1 if @a == the_amount_of_thread_ticks_to_wait # Do what you want break end }end
Doesn't need a Thread at all. Just add +1 to the variable in the update method of the scene and you are good to go.

The scene's update method is always running, no matter what, so that is the place you can put your own timers, etc.
Hmm... Okay, that would be a good solution

So I'll put @wait_time += 1 if @something_triggered into update method

In the code, that runs after something is done I'll put:

*SOMETHING WAS TRIGGERED* @something_triggered = true loop #< How to make a proper loop in script? ### Need a loop, because it's triggered only once. if @wait_time == 120 #do stuff @something_triggered =false @wait_time = 0 break # yup... end endWill this do?

lol or I could do simply:

Code:
*SOMETHING WAS TRIGGERED*  @wait_time = 0    loop #< How to make a proper loop in script? ### Need a loop, because it's triggered only once.      @wait_time += 1      if @wait_time == 120        #do stuff        break # yup...      end    end

Original thread: https://forums.rpgmakerweb.com/threads/ruby-rgssx-questions-that-dont-deserve-their-own-thread.150/