RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
Windows, Conditional Branches, and Scripting Tutorial

0 Members and 1 Guest are viewing this topic.

*
Meet me in the middle
Rep:
Level 89
or left of the dial.
For frequently finding and reporting spam and spam botsSecret Santa 2012 Participant
Okay, so, uh..lets get started. (TYPO IN TUTORIAL, I noticed I said to use armor, but I used sword by accident) (Demo at bottom).

Lets say you were making a blacksmith, you set a choice for an item to be created, but you want a window showing what is needed to make the item or whatever.Code:
Spoiler for:
Code: [Select]
class Window_Popup < Window_Base
  def initialize
    super(0, 0, 640, 64)
    self.contents = Bitmap.new(width = 600, height = 32)
    refresh  end
  def refresh
    self.contents.clear
#----------------------------------------------
#--Edit where it has purple text, if you want--
#--to be able to have more than just the same--
#--popup window, then copy this and rename it--
#--to something unique, you'll have to rename--
#--it where ever you see where I've placed my--
#--names, like to the left, and at the top of--
#--this, and don't forget to check the event --
#--that runs the script, you'll have to      --
#--rename that aswell.  When making the event--
#--put @gold_window.dispose AFTER the text,  --
#--it's important otherwise nothing pops up. --
#--        Have Fun!                --
#----------------------------------------------
        cx = contents.text_size("Creation Items: 10 Iron Bars,50 gold").width
    self.contents.font.color = normal_color
    self.contents.draw_text(0, 0, cx, 32, "Creation Items: 10 Iron Bars,50 gold", 2)
  end
end

Step 1:Make a new event, name it Blacksmith01 or whatever you want.
Spoiler for:

Shot at 2007-06-30
Now, put a Show Choice command and type "Make Iron Armor". Once your done that, under the "Make Iron Sword" option insert a "Script" command. Type "@gold_window = Window_Popup.new"(Explained at end of tutorial).
Spoiler for:

Shot at 2007-06-30
After that, put in another Show Choice option asking "Continue?" Then under the "Continue?" choice put another Show Choice command asking "Create Item".
Spoiler for:

Shot at 2007-06-30
Now the fun stuff, under the "Create Item" choice put a conditional branch, navigate to settings page 4 in the Conditional Branch options, check Gold or G or whatever your currency is and put 50.
Spoiler for:

Shot at 2007-06-30
After that,in the conditional branch, put a text command saying "Here you are." Then, a Change Gold command with settings of "Operation = Decrease" "Constant = 50" Then after that, put a Change Weapons "Iron sword Increase 1".
Spoiler for:

Shot at 2007-06-30
Under "Else" put a "Jump To Label" command and put whatever label name you want. (Everything explained at the end of tutorial)
Spoiler for:

Shot at 2007-06-30
Then after the "Jump to Label" command insert a script command with "@gold_window.dispose" (Also put this wherever necessary).
Spoiler for:

Shot at 2007-06-30
Then, at the bottom of everything, put an "Exit Event Processing" command.  Then under that, put a Label command. Put the same name as you did the Jump to Label command. Then insert text saying "Not enough gold."
Spoiler for:

Shot at 2007-06-30
Now if you go ingame, talk to the event and you have 50 gold, select the Create Iron Armor option and voilla a new Armor.
The Result:
Spoiler for:

Shot at 2007-06-30

EVERYTHING EXPLAINED!!

Starting with the conditional branch, I like to make my custom "shops" actually cost something :P. Which is why I used the Conditional Branch. For the Jump to Label, I used that to "jump" to the label below everything if the player did not have enough gold.
Now for the script explanation, the script is fairly simple to use, read the comments I put in it and you'll figure it out.(Put this script above "Main").
Spoiler for:
Code: [Select]
class Window_Popup < Window_Base
  def initialize
    super(0, 0, 640, 64)
    self.contents = Bitmap.new(width = 600, height = 32)
    refresh
  end
  def refresh
    self.contents.clear
#----------------------------------------------
#--Edit where it has purple text, if you want--
#--to be able to have more than just the same--
#--popup window, then copy this and rename it--
#--to something unique, you'll have to rename--
#--it where ever you see where I've placed my--
#--names, like to the left, and at the top of--
#--this, and don't forget to check the event --
#--that runs the script, you'll have to      --
#--rename that aswell.  When making the event--
#--put @gold_window.dispose AFTER the text,  --
#--it's important otherwise nothing pops up. --
#--        Have Fun!                --
#----------------------------------------------
        cx = contents.text_size("Creation Items: 10 Iron Bars,50 gold").width
    self.contents.font.color = normal_color
    self.contents.draw_text(0, 0, cx, 32, "Creation Items: 10 Iron Bars,50 gold", 2)
  end
end
-=DEMO=-
http://s23.quicksharing.com/v/6927608/WindowDemo.rar.html
Credit to Reddawg for the script.
« Last Edit: October 28, 2007, 05:56:15 PM by Firerain »

*
? ? ? ? ? ? ? ? ? The nice kind of alien~
Rep:
Level 92
Martian - Occasionally kind
Very nice tutorial ^_^

I edited the script a little bit. I feel this version is a little bit nicer to work with:
Spoiler for:
Code: [Select]
##
# Original script by Reddawg
# Editted by Zeriab
#
# Displayes a window popup
#
# @gold_window = Window_Popup.new
# When making the event put
# @gold_window.dispose AFTER the text,
# it's important otherwise the popup will stay.
#
class Window_Popup < Window_Base
  def initialize(text = "Creation Items: 10 Iron Bars,50 gold",
                 x = 0, y = 0, width = 640, height = 64)
    super(x, y, width, height)
    self.contents = Bitmap.new(width - 32, height - 32)
    @text = text
    refresh
  end
  def refresh
    self.contents.clear
    cx = contents.text_size(@text).width + 2
    self.contents.font.color = normal_color
    self.contents.draw_text(0, 0, cx, 32, @text, 2)
  end
end

You can use it like you do in the example.
If you want another text to be shown simply do this: @popup_window = Window_Popup.new("This is a popup window")
Remember to dispose the window when you don't want it shown anymore. (@popup_window.dispose)

 ~ Zeriab

*
Meet me in the middle
Rep:
Level 89
or left of the dial.
For frequently finding and reporting spam and spam botsSecret Santa 2012 Participant
Oh, cool. Thanks  :)

*
A Random Custom Title
Rep:
Level 96
wah
Nice. That's a lot of screenshots. I'd get tired of doing that. XD

*******
Rep:
Level 90
Returned from the dead.
Nice :P You learn something new everyday :P

Now I know how to call windows on the map :D
Sincerely,
Your conscience.

*
Meet me in the middle
Rep:
Level 89
or left of the dial.
For frequently finding and reporting spam and spam botsSecret Santa 2012 Participant
Nice :P You learn something new everyday :P

Now I know how to call windows on the map :D
Your welcome :)

*
Rep:
Level 87
I don't think your dispose is in the right spot.  If the player says No when given the Continue, No options, the window has been created but will not be disposed.  If the player chooses Create Item, the window will not be disposed.  If the player chooses Create Item but doesn't have enough gold, the Jump To NoGold will be executed before the window is disposed.  So I don't think your @gold_window.dispose command will ever be executed where it currently is.  You create the window before the Continue/No choice, so you should dispose the window after that whole block is completed.

Also, (I think) unless you've got extra processing in there, you don't even need the jump to when there's not enough gold - you could just pop your message in there right where the condition evaluates to false, and the if/else branching will take it straight to the bottom of the events anyway.  If you kept in the Jump, you'd need a second @gold_window.dispose to execute right before the jump, or right at the spot you're jumping to.

Here's a slightly modded version showing the above changes
Spoiler for:
If you think I've got something wrong please let me know - I still have a lot to learn.
« Last Edit: July 10, 2007, 11:39:55 PM by shaz »
Always remember you're unique.
Just like everybody else.

*
Meet me in the middle
Rep:
Level 89
or left of the dial.
For frequently finding and reporting spam and spam botsSecret Santa 2012 Participant
If you read the whole thing, you would've noticed I told you to put the dispose wherever else necessary. 

And the  JumpToLabel, I know about that already.

*******
Rep:
Level 90
Returned from the dead.
Nice :P You learn something new everyday :P

Now I know how to call windows on the map :D
Your welcome :)

Oh crap :P

Thanks a lot :P This'll help my games a bit :P
Sincerely,
Your conscience.