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.
Tsuno Sense Scripting Tutorial # 1 : "Hello World!"

0 Members and 1 Guest are viewing this topic.

*
Full Metal Mod - He will pillage your women!
Rep:
Level 93
The RGSS Dude
Hello lads and lassies, welcome to my second tutorial from a series of tutorials on anything from mapping to scripting.

Today we shall learn the mysteries of the epitome of all things that are programming.

"Hello World !"

Some of you may not have heard this phrase before, and I don't blame you. It used to be one of the most popular ways to teach apprentices of the computer how to program. I don't see it as much anymore, but it works all the same. It teaches you the basics.

RUBY is one of the most useful OO (object oriented) programming languages to have emerged.

Enough of the intro, let's get down to business shall we?

_____________________________________________

The very first funtion of RUBY we will learn is the print command. It is a pre-defined method that doesn't activate the printer (as it's name would imply), rather, it opens a prompt window with the text you supply.

There are four different ways to use this method.

Code: [Select]
print "Text Here"
print("Text Here")
print 'Text Here'
print('Text Here')

You may be saying, "What's the difference?", and you're right, there may not seem to be a difference. However, there is, but let's save that for a later lesson shall we?

Open a new event (give it a graphic) and add the script command.

In the text box, type -

Code: [Select]
print "Hello World !"

Now save, and test the game.

Walk up to and talk to the character, if you did everything correctly, a box should pop up with the words "Hello World!" printed inside it. Click okay (or cancel/X/whatever it is) and close the game window.

That was neat eh? But it doesn't look very professional, after all, there's some annoying quotation marks around the words.

Now I want to introduce you to a varient of the print command.

It's name? Simply p. The difference between print and p is simply that while print shows the quotations, p does not.

So go back into the event, and edit the script command to read the following -

Code: [Select]
p "Hello World !"

Test the game as before and

Hello World !

should appear without quotations in that window. (We will refer to window as a prompt)
Please correct me if I used the wrong term.

That's nice, but typing

Code: [Select]
p "Hello World !"

every time I want the message to show up seems lengthly doesn't it?

We will now create our very first method.

Open the script editor and create a new script at the top of the script list (easier to find). I recommend you name it (without quotes) "Hello World! ***" to keep track of it.

In the text field, type the following -

Code: [Select]
def hi
     p "Hello World !"
end

Let's go over what we just typed.

def tells the interpreter (what is running the scripts) that we are creating a new method. (def is short for define)

hi is the name of the method. Method names always start with a lower case letter and contain no spaces.

p "Hello World !". We should know what this is by now, please remember that the quotations identify the "Hello World !" as text.

end is kind of like the [/blah] tags in HTML and BBL. It tells the interpreter that we're done defining the method.

Now click okay and go back into the event.

Replace the script command text with the following.

Code: [Select]
hi

Test as usual, the same thing should happen as before.

Fun!

_____________________________________________

By now you're probably bored with "Hello World !".

So, let's personalize it shall we?

Firstly, replace the method we created earlier with the following.

Code: [Select]
def hi (name = "World")
     p "Hello #{name} !"
end

Let me explain the differences you see before you.

(name = "World") is what we refer to as an arguement. When we have name = "World", it's saying that if you supply nothing else when you run the method, name should be "World". Arguements are seperated by commas, and can simply be a variable.
(EX: (name = "World", age)

p "Hello #{name} !" is the same as before with one difference. Instead of pure text, it has #{name}. The #{name} is replaced with the value of the variable name in text form. Therefore, whatever name is, it will be included in the prompt.

NOTE: If you use #{variable} in text, you must always use double quotes, if you use single quotes it will print exactly as you typed it! I will explain this in a later lesson.

If you test the game as it is now, (please remember to save each time you make a change), it will once again say "Hello World !", so let's play with it a bit.

Go back into the event and edit the script command text to say the following.

Code: [Select]
hi("NAME HERE")

For me, I would do -

Code: [Select]
hi("Tsunokiette")

which will put out -

"Hello Tsunokiette !".

Neat eh?

While you may not think you've learned much, you really have. Let's go over what you just learned shall we?

_____________________________________________

You've learned the basics of how to use strings.
You've learned how to define a method.
You've learned how to integrate RGSS and Events.
You've learned how to use arguements.
AND
You've learned how to use the #{variable} funtion in strings.

This may not seem like a lot, but these are the most widely used tools in all of programming, it is what we use to test for errors throughout a script.

Until Next Time -
Tsuno Out
« Last Edit: December 09, 2006, 04:25:58 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."

****
Mne eto nado kak zuby v zadnitse.
Rep:
Level 89
U H N
2012 Most Attractive Female MemberLO !!f*ck u >:(^_________________^
This was really informative and I appreciated it a lot. Like, seriously. u r t3h pwn
an6uof hw to aLeme ozle we I

******
Revolution is not a bed of roses.
Rep:
Level 91
Project of the Month winner for July 2009
Nice, this should help a lot of new scripters :)

*
Full Metal Mod - He will pillage your women!
Rep:
Level 93
The RGSS Dude
Thanks peeps. (for lack of a better term xD)

(EX: "Thanks guy and woman" sounds kind of forced and strange)

Any other comments? I know I only spent like 20 minutes on this, but surely it helped.
"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."

********
EXA
Rep:
Level 92
Pikachu on a toilet
Project of the Month winner for April 2007
The p command is awesome during in-depth debugging. :D It saved my butt many times. Although I prefer making a debug window with constant information update sometimes.
Get King of Booze for Android, for iOS, for OUYA or for Windows!
Visit our website.
You can also love/hate us on Facebook or the game itself.


Get DropBox, the best free file syncing service there is!