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.
Scripting Ideas?

0 Members and 1 Guest are viewing this topic.

****
Rep:
Level 71
First off if this is better in scripts then can a moderator please move it? Any way does any one have any scripting ideas? I have my own but lack the skill to create them since I'm still learning. So does any have any ideas that aren't to difficult to do. To be honest all I really know how to do right now is scenes, though I can probably attempt a HUD.

***
Rep:
Level 77
RMRK Junior
Try a sound test/jukebox. Should be pretty simple...

****
Rep:
Level 71
I might try that, thanks.  :)

*
Rep:
Level 82
Quote
I have my own but lack the skill to create them since I'm still learning.

Don't be afraid to push out into deep waters. Often, it looks complex because there's many parts to it. Identifying those parts and tackling them one a time is a good (in my opinion the best) way to approach a problem. An idea is only as complex as you make it, too.

Doing a kind of jukebox is a good idea to start mingling together some things you'll run into.

If you need some pointers on what to look for, I'll be happy to provide some.  I don't want to put things up straight away for fear it might put you off a little.
(Why do I always feel like it's the end of the world and I'm the last man standing?)

****
Rep:
Level 71
Alright thanks, so far the only problem I would have trouble so far would be creating an array for the music and calling the array. If you could help me with this some time that would be great or if you knew of any tutorials that would better explain them.

*
Rep:
Level 82
The Help file does a decent job at giving you an idea of what you can do with arrays. This will be a lengthy post, because that's how I am. It'll also touch on making a BGM object and how you might go about playing the file if you make scene and window for it (which would be advised).

With Ruby, there's never a single way to do things. It was designed to be fairly flexible which makes it easy to pick up no matter what programming languages you might have used before, if any.

All you need to create an array is a variable name to tie the new object to, and then call the appropriate class' .new method.

Code: [Select]
@jukebox_data = Array.new

I prefer to write Array.new if I am making an empty array, but you can just do:

Code: [Select]
@jukebox_data = []

Which does the same thing. I like to be explicit with what I'm doing though, and it helps if you don't understand what '= []' does. I come from a C++ background, so I often carry over my coding style from there.

You can also initialize an array with values:

Code: [Select]
@jukebox_data = ["data1", "data2"]

The [] will make a new Array object for us (as if we used Array.new) and then add the contents to it and the variable @jukebox_data will be assigned to refer to the new array. You don't have to pass in strings; you can pass in variables if you want to or other such things.

If you use an array that already provides values like the one above, you won't need to worry about using .push, but I'll put it anyway.

Code: [Select]
object.push("music_filename")
#adds the given argument to the array. You can specify more than one thing by separating them with a comma:
#object.push("file1", "file2", "file3") would add 3 files. For now, I'd stick to just working with one file.

object[0]
#This is the 0th element or value of the object array and assigns it to the variable data. The 0th element is the first element in an array. Thus, object[1] is the 2nd element and object[15] is the 16th element in the array. It's just something you have to get used to is that.
#You can use a variable instead of a number, to change what value we get from the array.

object[i]
#This gets the ith (eye-th) element of the array. Whatever value i is, is the element we are looking at. If i is 5, it's the 6th element. If it is 10, it's the #11th. This is mostly seen when you use a for loop with i as the iteration #value to cycle through a whole array one element at a time.

new_var = object[1]
#We can also assign a variable to refer to the contents of an array at a given element.

Those two (technically four but three are the same idea) things, let you put things into an array and then look at what is in it at a certain location (index or element) within an array object.

In that example, the object only holds file names in a string format. They aren't actually music files, but the name of what the file is. We can use the idea of accessing elements in an array through a for loop to make use another array containing actual music files. I'm going to assume we are only using BGMs first.

Code: [Select]
@jukebox_musicfiles = Array.new #new empty array
@jukebox_filenames = ["filename1", "filename2", "filename3"]
for i in 0...@jukebox_filenames.size
  filename = @jukebox_filenames[i] #get the file name from the array at ith element
  music_file = RPG::BGM.new(filename) #create a BGM with the same file name as the value of filename
  @jukebox_musicfiles.push(music_file)
end

A quick note on the for loop. These loops will cycle over the code between the for and the corresponding end as many times as specified by start and finish. If we start at 0 and end at 5, we will iterate over the code in the loop
for each value from 0 up to 5. Thus we will go: 0, 1, 2, 3, 4, 5.

The format is:

for variable in start..finish
or
for variable in start...finish

'variable' is what iteration we are on starting from the 'start' value until we hit the 'finish' value. The dots between start and finish are important as they determine whether we include the finish value or not. With 2 dots, between 0 and 5, we will cycle 0, 1, 2, 3, 4, 5. If you we use 3 dots, we will cycle 0, 1, 2, 3, 4. 2 dots means inclusive, 3 dots is exclusive of the finish value.

Back to our code then: we use the value of i (our current iteration) to access to the values in our filenames array. The first iteration, 0, accesses the 0th element. The next iteration, 1, access the 1st element and so on up to the value of @jukebox_data.size. The method '.size' gets the length, or the size, of the array object. We have 3 data values in the array, so size is 3. Thus, our for loop is: ' for i in 0...3 '. We need 3 dots here, because there's isn't an element '3' in the array because it ends at 2 (@jukebox_data[2] is the 3rd and last item in the array).

Now, the variable @jukebox_musicfiles contains 3 BGM objects in an array. We can access these in the same way:

Code: [Select]
@jukebox_musicfiles[0] #the first music object
@jukebox_musicfiles[1] #the second music object
@jukebox_musicfiles[2] # the third music object

And we can also access them with a variable. If you look in Window_Item you can see this (and this will be helpful if you make a scene for this with a window):

Code: [Select]
  def item
    return @data[self.index]
  end

Whenever we call @item_window.item, we are getting the item that is held in the @data array at position 'self.index', which is the same value as the item that the cursor is highlighting currently. Like arrays, the first value on the list in the Item window is 0. This lets us access a value held at a particular, varying, element in the array.

We could have a similar set up in our own window that also plays the BGM associated with the data we get:

Code: [Select]
def play
  @jukebox_musicfiles[self.index].play
end

#which could also be written as
def play
  bgm = @jukebox_musicfiles[self.index]
  bgm.play
end

If this was an item list (which is basically would be), whenever we hit the enter key on an item we have highlighted, it will play the music file associated with it. This is what you want to try to achieve in the end.

There is a better way of doing this, like loading up a BGM object only after the enter key is hit so that we don't take up memory with a lot of music objects, but for the sake of learning how to use things, repeating the same steps is a good way to understand how to use things.

Hopefully that helps a little. I know it's pretty long, and I apologise for that. It makes it look like a lot more work that it actually is. There's quite a few tutorials out there, and Pacman wrote a pretty nice, quick read guide on a few things somewhere here. I'd try to learn what you can from the Help file too. It's is pretty helpful when you need to look up what methods or properties you have access in an object.

I'm definitely starting to think it would be worth writing up a guide of sorts. This only touches on a few of the surface things.

It'd be a long ass read though. I'd have to put pictures in it. Anyway, best stop typing or it'll be too long to post.
« Last Edit: February 23, 2012, 08:46:21 AM by Logan »
(Why do I always feel like it's the end of the world and I'm the last man standing?)

****
Rep:
Level 71
No need to apologize for the long post and this helped me a lot. I'm finishing up a HUD script and after that I'm going to start immediately.

*
Rep: +0/-0Level 72
RMRK Junior
@logan

That was one of the best ways to describe arrays and iterations I saw in a long, long time. You sir, are awesome!

Wishing you well,
~Faal