Posted: Tue Jun 24, 2008 1:14 pm Post subject: Guitar hero Help
Ok so what im really wanting help with is positioning the keys. I know a longer way of doing this (see lines 431-434) but im just wondering is there a faster way of doing this because I don't feel like placing the keys 914 times (only have 105 done) anyways Can someone help me so this can be done faster? But still keeping the game the way it is. Also is there some things i can do in the code to make it more neat? open to all comments and ideas
GUITAR HERO DEATHBRINGER.zip
Description:
This is my game file read obove for what I need help with.
Posted: Tue Jun 24, 2008 2:56 pm Post subject: Re: Guitar hero Help
Well, I'd like to offer some help, but when I try to run it, I get "illegal picture ID number '0'. (On line 32). Did you forget to include one of the pictures?
Also, its very difficult to see how to help (starting line 431) when your code is not properly indented. When its all in one huge horizontal line its very hard to read
and understand. If indentation is not a habit, I suggest using ctrl+i , which does it for you. In this case, since there is so much to indent Turing does not have
enough memory to indent it. I began to do it manually, and I think I see the pattern in your code which can probably be simplified using loops. Otherwise, to quicken a long sequence of ifs you can use elsifs.
Heres my suggestion based on a small section of that big line of ifs. I based it on my assumption that your comparisons are always going up by twos, and your assingment to the variable notesdiff is going from 1 to 5 then back down to 1 (1,2,3,4,5,4,3,2,1,2,3,4,5 and so on). If this pattern does not continue, the following code may not work for all the way to 914 notes or whatever.
if totalnotes > 1 then
DIFF := 150
elsif totalnotes > 3 then
notesdiff := 3
elsif totalnotes > 5 then
notesdiff := 4
elsif totalnotes > 7 then
notesdiff := 5
elsif totalnotes > 9 then
notesdiff := 4
elsif totalnotes > 11 then
notesdiff := 3
elsif totalnotes > 13 then
notesdiff := 2
elsif totalnotes > 15 then
notesdiff := 1
end if
However, the above will not help in your case, since Turing looks over these ifs chronologically, and once one of them is met, the check is complete.
Ex. if totalnotes is 4, the first if just wants greater than 1, and 4 is greater than 1, so notesdiff would be 1. I am guessing that you want notesdiff to
be 3 when totalnotes is 4. You'll have to fix that for checking if totalnotes is between certain numbers.
Your ifs check greater than 3, and then greater than 5. Im guessing your greater than 3 wants the numbers that are greater than 3, but not greater
than 5, meaning the numbers 4 and 5 are acceptable. You'll need two checks in each line to do that:
code:
if totalnotes > 1 and totalnotes<4 then
DIFF := 150
elsif totalnotes > 3 and totalnotes<6 then
notesdiff := 3
elsif totalnotes > 5 and totalnotes<8 then
notesdiff := 4
elsif totalnotes > 7 and totalnotes<10 then
notesdiff := 5
elsif totalnotes > 9 and totalnotes<12 then
notesdiff := 4
elsif totalnotes > 11 and totalnotes<14 then
notesdiff := 3
elsif totalnotes > 13 and totalnotes<16 then
notesdiff := 2
elsif totalnotes > 15 and totalnotes<18 then
notesdiff := 1
end if
Now thats still a lot of code to go all the way to 914, but the between checks are always going up by twos, and notesdiff is 1 to 5 and down to 1.
The following should help, although the loop is still a little lengthy ( still shorter than 914 lines or so )
code:
for interval:1..number_notes by 16 %you can treat 1,2,3,4,5,4,3,2 as one block, which is 8 numbers
%but each check is by twos, so you'll go by 16, which will continue
%that cycle
if totalnotes>interval and totalnotes<(interval+3) then %if its between say 1 and 4, then its 1
notesdiff:=1
elsif totalnotes>interval+2 and totalnotes<(interval+3+2) then %if its between 3 and 6, then its 2 (and so on)
notesdiff:=2
elsif totalnotes>interval+4 and totalnotes<(interval+3+4) then %I showed it in +3 and +4 instead of +7 so you see the pattern
notesdiff:=3
elsif totalnotes>interval+6 and totalnotes<(interval+3+6) then
notesdiff:=4
elsif totalnotes>interval+8 and totalnotes<(interval+3+8) then
notesdiff:=5
elsif totalnotes>interval+10 and totalnotes<(interval+3+10) then
notesdiff:=4
elsif totalnotes>interval+12 and totalnotes<(interval+3+12) then
notesdiff:=3
elsif totalnotes>interval+14 and totalnotes<(interval+3+14) then
notesdiff:=2
end if
end for
I hope that helps quicken your task, although I cant get your code to run, so I don't know if it works properly, or If I made some errors.
It still seems like I could shorten the loop a little. Oh well, i hope I at least gave you some ideas of how to use loops to help you shorten lengthy ifs.
Good luck, and I look forward to seeing the finished product
DemonWasp
Posted: Tue Jun 24, 2008 3:25 pm Post subject: RE:Guitar hero Help
First, to answer your specific question: it looks like you're repeatedly setting notesdiff based on which note the player has gotten to in the song (or something like that). This can be done MUCH better by using an array of notesdiff values; you can then load all those values from a file using maybe 10 lines of code, total.
This provides the additional massive benefit that you don't have to hard-code every single song - you can just choose your [song name].song file and then run using that. I can provide additional hints and help if you need them, but you're probably better off thinking it through on your own first.
Also, congrats on using types - they're one of the topics that isn't part of the standard curriculum, as I recall. I certainly wasn't taught types in school until grade 12.
To make your code better:
This isn't intended to be harsh criticism, just stuff you should do to make your code better. Just because you don't do all of these doesn't make you a bad coder - but doing all of them will make your code much easier to read, maintain and help with. So, in no particular order:
1. Choose more descriptive variable names. I know that "notesdiff", "multiply" and so on make perfect sense to you right now, but they don't mean very much to me, or anybody else - and if you left the code alone for 6 months or so and then came back, you'd probably experience the same effect. Generally, the standard is something like "how it would read in a sentence"...so instead of "diffgame", one of "gameDifficulty", "game_difficulty", "GameDifficulty" would be expected. Capitalisation and use of underscores depends on environment, language, and your coworkers (though Turing has no established standard for how to name variables / functions / procedures / types).
2. Comment to describe HOW things work. It's good to start with "these are the end game functions", but without any explanation of what each part does, and how it does it, I'm pretty lost. Reading the code takes a lot longer than reading a comment, and writing a comment doesn't take long at all. It also helps out a lot if your comment is different from what the code seems to be doing - then you know one of the two is wrong.
3. Try hitting F2. Your code should be properly indented at all times. It makes blocks (if-end if , loop-end loop , for - end for , proc - end , function - end, etc) MUCH more obvious, and makes determining the flow of control way easier. Alternately you could indent properly on your own (I did this, as I had a different indentation scheme than Turing liked - less spacing out).
4. This is a recommendation in general, but I'm going to use a specific example to show it. In a few different places you have a lot of equations with the same computation in them, such as "sqrt (node (i).p.z)))". In this case, for both readability and performance, it's best to make a temporary variable (a descriptively-named one) that stores that value and is used in the calculations. That way, you don't have to do "sqrt (node (i).p.z)))" over and over and over.
death bringer
Posted: Tue Jun 24, 2008 8:04 pm Post subject: RE:Guitar hero Help
Ok for line 35 just delet it sorry and you can run the program also i will look over my code and use what you have said anything else I should know or does anyone also have a faster way of doing this?
DemonWasp
Posted: Wed Jun 25, 2008 7:35 am Post subject: RE:Guitar hero Help
On running the game, it looks like you've done a pretty good job. Some nitpicks/advice:
Unrelated to speed, some suggestions on the game:
1. You really need some better feedback about whether I'm missing or hitting notes - I can't tell if I am or not.
2. That song is insanely hard, and I'm a terribly Guitar Hero player. If you switch to using files, I can play something more my speed (perhaps Mary had a little Lamb).
3. As mentioned, I'm terrible. Even so, I was able to hit a 700 note streak before the song ended. How? Your program checks that I hit each note, but it doesn't actually check that I strum for each one, so if I just hold down Enter and hold down the right keys for the notes, I get them. It also doesn't appear to check that I don't press other keys (ie I shouldn't be able to play 3 keys if it only wants one, but I can).
4. What the devil are those box things? They're annoying, and appear to be malfunctioning.
5. Cute loading screen, but you should know it looks a little fake (nothing ever loads that smoothly).
6. Generally, a GH game starts with a little bit of space between where you have to hit the notes and where they start.
7. You might want to draw pegs that are further away before ones that are closer - this prevents weird issues with further pegs appearing over nearer ones.
8. The multiplier display doesn't like actually displaying a number until I get to X8, where it sticks.
Speed-wise, I really can't comment. The machine I'm on is basically the supercomputer of home systems, so I had absolutely ZERO speed issues. If you can give more information about what "feels" slow, then I may be able to help you there.
death bringer
Posted: Wed Jun 25, 2008 11:16 am Post subject: RE:Guitar hero Help
Ok I also Might decide To do a song from guitar hero 3 the one im playing on (I Play Expert thats why my programs so hard sorry ;p also in the past i had my guitar hero using random integers so you could change diffgame (a var) and diffgame would affect speed, spacing, and make it easy medium or hard. For the multiplier I know it some what jibs out but To get the star power going and make the multiplier double is causeing problems mathimaticly also what do you mean by those box things? loading screen is fake but it was mainly to prepair the player form the game so he/she has more time to get ready.
(PS. all acuall loading is done before running) Also the speed is the running without lagg if thats what you are saying it's just the game spacing i would like to be able to change it but whenever I attempt to change the var DIFF nothing happens know how i can fix it? Lastly for the difficulty I would have to keep it at a consitant because i dont know what i would do for positioning if the diff was changed (i'm sure it would take a long time for me to do this)
anyways again thank you and iif possible post more thing i can maybe do to make this program better cause i am starting to reach my limit of what i think I should do next.
kk now im goping to play my acuall guitar hero so i can find a good son to use for my program.
DemonWasp
Posted: Wed Jun 25, 2008 12:50 pm Post subject: RE:Guitar hero Help
First, I have a request: think through what you're going to post as clearly as you can, and post in complete sentences, with paragraph spacing, and a clear explanation of what you need / don't understand / want help with. I know this makes me sound like an ass, but I'm much more willing to help people who can communicate clearly. I'm having trouble understanding what you're wanting help with at times.
A lot of your problems seem to be with selecting difficulty for the song. Rather than doing something in your code, it's probably best to have something like this:
Then, when the player selects their song, you can just look for the _hard, _medium and _easy files, and give them only the options that are available. Once they choose, load the .song file they chose and play that. This lets you use a different set of notes for each easy, medium and hard, as well as allowing for more than one song.
Try to implement that (make a backup copy of your code before making changes), then get back to us. Oh, and post an updated version of your code.
SNIPERDUDE
Posted: Wed Jun 25, 2008 3:46 pm Post subject: RE:Guitar hero Help
death bringer seems to have organizational problems, lol.
But all doesn't seem to lost quite yet, thanks DemonWasp for helping out and taking your time to help others.
Sponsor Sponsor
death bringer
Posted: Wed Jun 25, 2008 7:40 pm Post subject: RE:Guitar hero Help
I do have trouble organizing, and spelling, all grammer, and well really just all of my english....
But I was starting to think of a way to do this positioning and still keep the same song
1. bring back my diffgame var for use
2 if diffgame=3
then fork easy
else if diffgame=4
then fork medium
else if diffgame=5
then fork hard
3 process easy
(then I do if's and else if's)
end easy
process ect ect
DO you think that this may work i will get back to you if it does or I find a new way of doing this.
DemonWasp
Posted: Wed Jun 25, 2008 8:44 pm Post subject: RE:Guitar hero Help
It will work, but it's NOT an ideal way of solving the problem. The solution I have given you will make for a better program (and be easier to maintain). I'll describe it more clearly below. And thanks for posting more legibly.
You'll want something like this:
1. Player chooses [easy, medium, hard]
2. Load the song-file for their choice. It can still play the music from the "deathbringer" song you already have, all it has to do is read in a different set of notes for the player to play. Your file could look like the following (very basic version of the game, like what you have right now).
3. Play the game, using the information loaded from the file.
Example: deathbringer_easy.song (defines what keys need to be pressed.
...etc. In this scheme, each line represents a set of keys to press at that time; a dash (-) means "don't press this one", while x means "you'd better press that one though". You would then use the lines of five dashes (-----) as spacers between the notes (remember, this is on easy). In the hard file, you might have something more like this:
You'll note that these sections both take the same length of time (10 lines), so they'll line up with the song the same ... but the "hard" version would be substantially more difficult.
If you need help figuring out how to load the file, I can help you with that. I'm deliberately trying to leave some problems for you to solve on your own here.
SNIPERDUDE
Posted: Wed Jun 25, 2008 9:42 pm Post subject: RE:Guitar hero Help
I saw one version where it was something like this, although I recomend what Demonwasp suggested
code:
00100 10
01010 5
01000 5
etc...
the first 5 are the frets obviously, and the number that follows is the delay time.
EDIT:
All of this talk about guitar hero makes me want to make a version, but that is at the end of a very long line of projects underway right now.
ANYWHO good luck to you.
death bringer
Posted: Wed Jun 25, 2008 10:23 pm Post subject: RE:Guitar hero Help
OK I domewhat get what your saying but
How would i do the vars for this?
--x--
-x---
x----
-x---
--x--
---x-
----x
for example
PS I found out what was wrong with my Spacing and now i can control it (will post neater file l8r)
DemonWasp
Posted: Wed Jun 25, 2008 11:03 pm Post subject: RE:Guitar hero Help
You could choose a lot of different variables to represent that. Consider exactly how it needs to be used:
1. Must be readable, one line at a time, from a file. This should take you perhaps 10 lines. I'm fairly certain you could do it in 4 if you thought about it for a minute.
2. Must be accessible to determine which notes are being played at any point in time.
So basically you just have to store a long (but known-length) set of lines (each of which is a string).
So, I would use an array of strings (keep in mind that you need to know the size of the array when the song loads, so you may want to put that at the top of the file):
code:
7
--x--
-x---
x----
-x---
--x--
---x-
----x
Then your access code should be really, really easy, as should your loading code - just check whether the character at the key-index (1 for the left-most, 5 for the right-most) is a dash or an X.
death bringer
Posted: Wed Jun 25, 2008 11:24 pm Post subject: RE:Guitar hero Help
wow ok to be honest i dont know how i would still do this cause I ju finished grade 9 and I really was teaching myself how to use turing so um can you give me an example or help me out a bit cause I still don't know how to do the varriables for that I'm not the best in turing yet cause I learned from observeing
(ps I do understand a bit of what you are saying demonwisp but i just don't know what triggering i would use) would this be using arrays and vars or const also how would i get turing to read thats it's a space ( - ) or a key (x) I need more info for this.
Also i don't mind any critisism
DemonWasp
Posted: Wed Jun 25, 2008 11:46 pm Post subject: RE:Guitar hero Help
Let me give you some more "formal" education then. Since you're not working on a summative project, I'll be more helpful than I would normally be.
"var" stands for "variable", which means that the value held by that thing can be changed (ie it can be 5 one moment, then 10 the next, etc).
"const" means that it's a "constant", so it never changes. Some examples you may already know are pi = 3.141592... and e = 2.718... .
"array" just means that it's a table of either variables or constants (or records, when you get to that point). Basically it's just a bunch of things that you can get the Nth one from at any time.
To get the value of a variable or constant, you just use its name. To get a single value from an array, you use it's name and a number:
arrayName ( indexNumber )
To solve your problem, you will need an array, capable of storing the same number of lines as you have in your file, of strings. You can do this like so:
Turing:
% Open a file for input. The "fileId" variable is used by Turing to track which % file we want to access; "filename" should be replaced by the name of the file % you want to load, and "read" means that we're reading from the file (using % "get" only, never "put"). var fileId :int open: fileId, "filename",read
% Variable initialisation for storage of the notes. var numNotes :int% Contains the number of notes in the song get: fileId, numNotes % Get the number of notes from the song (first line) var notes :array1..numNotes ofstring% Make an array that's just big enough
% Load the notes from the file. Each element in the array will represent the % n-th set of notes in the song. Once this has completed, you can access the % n-th line in the song with < notes ( n ) > for i:1..numNotes
get: fileId, notes ( i ) endfor
For each line in the file, you can then determine which is a space and which is a note by using an index into the string (it's like an array - the first letter is at (1), the second at (2) and so on). You would do something like:
notes ( lineNumber ) ( noteIndex )
where lineNumber is the number of the line you're looking at, and noteIndex is the number of the note (1 is leftmost, 5 rightmost).
If you have problems understanding or implementing that, I can help more, or we can move onto the next step of implementing the program. I'll wait for your response.