[VXA] Biography Scene by VianoceGames

0 Members and 1 Guest are viewing this topic.

***
Rep:
Level 31
RMRK Junior
Original Post:
Quote
Hello everyone,

I am really new to scripting and this is my second script after watching the tutorials by DP3 on YouTube. The first one is a quest Journal that i had written while following along DP3's tutorials. The scene in this topic is of the first script I written solo as a result of what I have learned so far from his teachings. I am proud of what I have accomplished with it so far but I unfortunately got stuck and cannot complete the script without help. What I need is for a way to cycle through my array to appear to change pages or w/e. I made the array into a $game_system variable and I plan on making it so the array can be updated through event script calls too. I want to try that on my own I just need help getting it to cycle through the array when the player presses the right or left keys.

I made a variable to try to help cycle through the array but for some reason when I tried to use it I kept getting an error reading:
NoMethodError undefined method '[]' for nil:NilClass. To combat this I turned the variable into another $game_system variable and initialized it to 0. This worked in getting the database to work when it was called, but nothing happens when the variable is changed with frame update. If anyone can help I would greatly appreciate it.

Edit: The script s ready to use and has been updated here.

Here is a screen shot of what it looks like right now:

It still needs a little work to get it to do what I want it to do 100%. However it is working beautifully, so for now I am going to leave it as it is so I can work on my project a little. 

I would like to thank pacmn and Tsunokiette for their help and advice.

Here is the script:
http://pastebin.com/embed_iframe.php?i=RH7ujq4s
« Last Edit: February 26, 2015, 11:51:34 PM by VianoceGames »

*****
my name is Timothy what's yours
Rep:
Level 79
Hello
2014 Zero to Hero2014 Best IRC Quote2014 Most Missed Member2012 Zero To HeroSecret Santa 2012 ParticipantContestant - GIAW 9For frequently finding and reporting spam and spam bots2011 Zero to Hero
The problem is that the windows aren't being refreshed. The information is changing, the system variable gets it, the scene gets it, even the windows get it, but the windows aren't being told to redraw their information. Basically all you need to do is put a 'refresh' method in to each of your windows. Here's my example for your Window_Biography_Name:
Code: [Select]
def refresh()
  contents.clear
  draw_name
end
The last step is to run these methods when the scene scrolls left or right:
Code: [Select]
  def scroll_right
    scroll_se = "Decision3"
    RPG::SE::new(scroll_se, 70, 100).play
    $game_system.char_index_array += 1
    @window_biography_name.refresh
    @window_biography_image.refresh
    @window_biography_bios.refresh
    @window_biography_cgs.refresh
  end

Quick tip while we're at it, it's general convention to protect arguments when aliasing a method to increase compatibility with other custom scripts.

Code: [Select]
class SomeThing
  def actual_method(bibbidy, bobbidy, boo)
    do_some_things(bibbidy, bobbidy, boo)
  end

  alias new_actual_method actual_method
  def actual_method(*args)
    new_actual_method(*args)
    do_more_things
  end
end
What (*args) does is preserves all arguments given to a method and then recalls them. This means if another scripter added arguments to a method, you can alias it without fear of losing their changes as well.

Hope I helped!

***
Rep:
Level 31
RMRK Junior
Thanks Pacman! You were very helpful. I thought I did alias everywhere I needed to. Could you show me where I missed?

*****
my name is Timothy what's yours
Rep:
Level 79
Hello
2014 Zero to Hero2014 Best IRC Quote2014 Most Missed Member2012 Zero To HeroSecret Santa 2012 ParticipantContestant - GIAW 9For frequently finding and reporting spam and spam bots2011 Zero to Hero
It's not that you weren't aliasing in some places, it's that you should use (*args) to make sure you're not losing any information being fed to the method, or creating any wrong number of arguments errors.

***
Rep:
Level 31
RMRK Junior
Ok, thanks for the tip!

***
Rep:
Level 31
RMRK Junior
I updated my pastebin with the corrections you gave me. The *args gave me errors when I tried to put them in for some reason. I also moved the bits of code for the character image to the actual window instead of in the start processes so the refresh could effect it and I used  .dispose the the method you gave me to dispose of the image before it change because it was just stacking the image. I can't get the if statement to work at all to keep from getting the nil error when the refresh cycles through the array size.

***
Rep:
Level 31
RMRK Junior
I gave up on trying if statements and now I'm trying return unless instead. I have updated my pastebin again. I only got the unless statement to work for one of the frame update methods. I really thought I had it this time but it seems like I'm only making baby steps...

This works fine.
Code: [Select]
 
  def scroll_left
    scroll_se = "Decision3"
    RPG::SE::new(scroll_se, 70, 100).play
   
    return unless $game_system.char_index_array > 0
    $game_system.char_index_array -= 1
       
    @window_biography_name.refresh
    @window_biography_image.refresh
    @window_biography_bios.refresh
    @window_biography_cgs.refresh
  end

But this  doesn't. It still allows it to exceed the array.size
Code: [Select]
  def scroll_right
    scroll_se = "Decision3"
    RPG::SE::new(scroll_se, 70, 100).play
   
    return unless $game_system.char_index_array <= $game_system.biography_chararray.size
    $game_system.char_index_array += 1
   
    @window_biography_name.refresh
    @window_biography_image.refresh
    @window_biography_bios.refresh
    @window_biography_cgs.refresh
  end
« Last Edit: February 25, 2015, 04:08:34 AM by VianoceGames »

***
Rep:
Level 31
RMRK Junior
WOOT! I got it to finally work. I tried it before and it failed, but maybe it didn't work because I was using <= instead of just <. What I did was add - 1 on the end again and it worked! Not to add more code to screw it up... >.<

I updated my pastebin at the top with how it is working now.

How it looks now:
Code: [Select]
  def scroll_right
    scroll_se = "Decision3"
    RPG::SE::new(scroll_se, 70, 100).play
   
    return unless $game_system.char_index_array < $game_system.biography_chararray.size - 1
      $game_system.char_index_array += 1
   
    @window_biography_name.refresh
    @window_biography_image.refresh
    @window_biography_bios.refresh
    @window_biography_cgs.refresh
  end

***
Rep:
Level 31
RMRK Junior
Btw Thanks Pacman for you help! I wouldn't have gotten this far without you!

***
Rep:
Level 31
RMRK Junior
Woot! The script is "done" and usable, although I do plan on updating it in the future. The pastebin in my first post has been updated.

*
Full Metal Mod - He will pillage your women!
Rep:
Level 93
The RGSS Dude
You could also use a modulus if you want to be able to scroll back to the beginning after you've reached the last bio page. Assuming I'm understanding what you're doing correctly.

Code: [Select]
$game_system.char_index_array = ($game_system.char_index_array + 1) % $game_system.biography_chararray.size
"The wonderful thing about Tiggers
Is Tiggers are wonderful things
Their tops are made out of rubber
Their bottoms are made out of springs

They’re bouncy, trouncy, flouncy, pouncy
Fun, fun, fun, fun, fun!
But the most wonderful thing about Tiggers
Is I’m the only one, I’m the only one."

***
Rep:
Level 31
RMRK Junior
Yeah I wanted it to do that but I couldn't figure out how to do it. This is the 1st script I have written without watching a tutorial.

*
Full Metal Mod - He will pillage your women!
Rep:
Level 93
The RGSS Dude
Edited it into my previous post. I think the math is right. Just woke up lol.
"The wonderful thing about Tiggers
Is Tiggers are wonderful things
Their tops are made out of rubber
Their bottoms are made out of springs

They’re bouncy, trouncy, flouncy, pouncy
Fun, fun, fun, fun, fun!
But the most wonderful thing about Tiggers
Is I’m the only one, I’m the only one."

***
Rep:
Level 31
RMRK Junior
So I put that into a module? Then I call the module from the frame update? How will I get it to work both ways?

*
Full Metal Mod - He will pillage your women!
Rep:
Level 93
The RGSS Dude
For scrolling right you just use modulus to get the remainder after dividing the index by the number of elements in the array (the array size).
I.E. 7 % 8 = 7 ; 8 % 8 = 0 ; 9 & 8 = 1
I don't know specifically which variables are which, so what I typed specifically may be incorrect, but it's the general idea. It would also prevent you from going out of bounds. There's a very small chance you might get a stack overflow, but the player would have to open the scene and scroll right (depending on the data type) upwards of 2 billion times lol.

For scrolling left, you would minus 1, then check to see if the index is less than 0. if it is, then set the index to be equal to the final index in the array.

Similarly you could also just check if the index is >= the array size (so the index would be out of bounds) then just set the index to 0. I just happen to be a fan of the modulus operator personally lol. but doing it this way would allow you to be consistent in how you are approaching the solution and also avoid a stack overflow from a player who is hellbent on reaching one.
« Last Edit: February 25, 2015, 05:36:52 PM by Tsunokiette »
"The wonderful thing about Tiggers
Is Tiggers are wonderful things
Their tops are made out of rubber
Their bottoms are made out of springs

They’re bouncy, trouncy, flouncy, pouncy
Fun, fun, fun, fun, fun!
But the most wonderful thing about Tiggers
Is I’m the only one, I’m the only one."

***
Rep:
Level 31
RMRK Junior
Thanks I will give it a shot! I appreciate you helping. I'll be back in a bit though. I have to run to the store, then make lunch.

 

*
Full Metal Mod - He will pillage your women!
Rep:
Level 93
The RGSS Dude
If you wanted to get really fancy and do everything in one line you could use a ternary operator.

variable = conditional statement ? value if true : value if false

So for scrolling to the right

Code: [Select]
index = index + 1 >= array_length ? 0 : index + 1

And for scrolling to the left

Code: [Select]
index = index - 1 < 0 ? array_length - 1 : index - 1
"The wonderful thing about Tiggers
Is Tiggers are wonderful things
Their tops are made out of rubber
Their bottoms are made out of springs

They’re bouncy, trouncy, flouncy, pouncy
Fun, fun, fun, fun, fun!
But the most wonderful thing about Tiggers
Is I’m the only one, I’m the only one."

***
Rep:
Level 31
RMRK Junior
That does look pretty snazzy.