Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / HELP! (My help thread.)

Author
Message
Darkzombies
13
Years of Service
User Offline
Joined: 25th Dec 2010
Location: In multiple tabs, most likely youtube.
Posted: 14th Oct 2011 07:55 Edited at: 15th Oct 2011 05:10
Ok, so Im having this problem, the playerinput glitches out. And load/save is getting errors (I don't know why!)

So here:



EDIT: Problem Fixed! SEE BOTTOM FOR MOST RECENT PROBLEMS!

"Insert funny coding-related joke here"
Kezzla
16
Years of Service
User Offline
Joined: 21st Aug 2008
Location: Where beer does flow and men chunder
Posted: 14th Oct 2011 08:10 Edited at: 14th Oct 2011 10:07
well, i can see a couple of things,
true is a reserved keyword so you cant call your constant that.

also you have put the loop condition until downk = 0 but you have set the constant downk to the original value of downkey() which was not being pressed during declaration, so downk will always = 0 try using variables instead of constants for that.

ive never really played with write long, but it seems you've entered the values incorrectly

WRITE LONG File Number, Variable
where you have
write long 1, player, knight, civilian, troops, maxtroops, civs
write long 1, maxcivs, houses, entroops, maxentroops, gold, seiges
write long 1, defences

there's some stuff for starters(im writing this as i go through the code.
hope this helps.
kezzla

Sometimes I like to use words out of contents
Darkzombies
13
Years of Service
User Offline
Joined: 25th Dec 2010
Location: In multiple tabs, most likely youtube.
Posted: 14th Oct 2011 08:52 Edited at: 14th Oct 2011 08:58
Oh I see, but actually, with the WRITE LONG thing, I was going to change that to fit the load() function, but I was having errors so I forgot to, please look at that. I don't see why its not working.

EDIT: Ok... still not working, I changed the constants to variables



"Insert funny coding-related joke here"
Kezzla
16
Years of Service
User Offline
Joined: 21st Aug 2008
Location: Where beer does flow and men chunder
Posted: 14th Oct 2011 10:04
not sure of your end goal with your layout, but it seems to me you are making it all a little over complicated.

why not try something like



that way the command will repeat every loop until the key is not pressed.

I don't see any immediate use for your constants(but ive just had a brief look and don't know your end goal)

I dont really use file commands too much but it seems to me like this would work better with the following format

write long 1, player

but even still, your trying to save a UDT with no actual data assigned to the variable player.

maybe try simplifying your layout, work on getting a model of the game working first and then focus on loading and saving game files.

good luck, sorry I couldn't be more help.

kezzla

Sometimes I like to use words out of contents
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 14th Oct 2011 10:30
Quote: "true is a reserved keyword so you cant call your constant that."

Are you sure about that Kezzla? It doesn't highlight for me.

@ DarkZombies: Where do you declare dir1, dir2 and dir3? If you are declaring them in the functions then each time that function is called they will be set to 0.

I also highly recommend Kezzla's way of moving the sprites but if you wish to keep your current system you'll need to call this each loop.



zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 14th Oct 2011 13:56 Edited at: 14th Oct 2011 22:32
I will try to work on this for a little while, but just glancing at the code... I think it would be in your best interest to take some time and work through some of tutorials on DBpro principles. There are numerous threads that will come up using the forum search as well as "stickied threads" on boards listing them.

edit

I fixed some of the code. I will have to edit your code here so that I can grab blocks of color to represent images, to test further. Some other suggestions...

1. Either declare and initialize all of your variables at the top of your program, or call a subroutine via a gosub, to initialize them. If you don't you run into a chance that you attempt to use variables before they are defined or given a value

2. Ease up on the functions, as many of yours would serve better as subroutines. Generally functions are good when you need to pass it variables,, perform some calculation, AND return a result.

3. Variables that you assign values to inside of functions are only available to that function. Unless... you declare a variable as a global ( or it is defined outside of a function) or you use a return variable. Check out the help on functions, and how to return values . I tend to make a lot of variables global in scope, while not everyone does that, I find it causes me less issues, and I don't have to pass every function, every outside variable. Others may feel that it isn't good practice, but I think if you are careful it's a lot easier. Either way, you need to have an understanding of the DB principles.

4. I REMMED out your save and load functions. You really need to understand how they work (eg... you can't place multiple variables separated by commas. It's not how the command works. My suggestion is to use the "write string" & "Read String" commands for all your variables. Just convert any non-string variables to a string by using str$(variable) and convert them back by using val(variable) when reading. I don't use the other read and write commands, honestly because I don't understand them. I can write and read them from within dbpro, but I am lost about how to create them on my own in a textfile. Maybe someday I'll get around to it. Anyways, and it's one variable per Write command, to keep it simple. If you want to write numerous variables you can have a string variable temp_var$... convert your other variables to a string and then add them to the temp_var$ like.... temp_var$=var1$ + var2$ + var3$. Though you will then have to parse the string when you read it back. Check out some code snippets on the file write and read commands. Or download Ianm's matrix1utils dll, for improved file commands. Maybe I shouldn't be giving advice on file commands. LOL!!!!

I would have to few the file with a hex editor to have a beter understanding of the other read and write commands. It just seems easier to work with strings and see the data.



Your signature has been erased by a mod please reduce it to 600 x 120.
Kezzla
16
Years of Service
User Offline
Joined: 21st Aug 2008
Location: Where beer does flow and men chunder
Posted: 14th Oct 2011 14:29 Edited at: 14th Oct 2011 14:35
Quote: "Quote: "true is a reserved keyword so you cant call your constant that."
Are you sure about that Kezzla? It doesn't highlight for me. "


hmmm, it must be one of my plugins that uses it. with my setup I cant use "true". Not sure which plugin it is, ill have to look into it.
edit: I can use it as a variable but not as a #constant which throws up the error
Quote: "Constant name 'true' cannot share the name of a reserved word or command."
:edit

kezzla

Sometimes I like to use words out of contents
Darkzombies
13
Years of Service
User Offline
Joined: 25th Dec 2010
Location: In multiple tabs, most likely youtube.
Posted: 14th Oct 2011 19:01 Edited at: 14th Oct 2011 19:31
Gah! I know im a noob you don't have to tell me. Im just tired of watching tutorials, I want to learn on my own. Thanks for the help.

EDIT: Ok, I took all your advice, now whatever I do, the left/right moving is always inverted, and the character teleports to the bottom left corner at the very beggining.



EDIT TWO: Okay, now I added mirror sprite commands, thats working (Note the inverted bug isnt fixed)
But it glitches out when you press two arrow keys at the same time.



"Insert funny coding-related joke here"
Kezzla
16
Years of Service
User Offline
Joined: 21st Aug 2008
Location: Where beer does flow and men chunder
Posted: 14th Oct 2011 19:26
Quote: "Gah! I know im a noob you don't have to tell me. Im just tired of watching tutorials, I want to learn on my own. Thanks for the help."

nothing to stress about, I'm still a noob too.

I think just make small test projects testing out different ideas for your final goal.

keep it very simple and work your way up.

if it doesnt work go back to a place where it does work and make sense.

game logic has to make sense to you or else it simply isn't logic it's jibberish.

gotta go back to where it makes sense and build.

I recomend TDKs tutorials, they are truely exellent. search for them in TGC forums, you will find them.
best of luck

kezzla

Sometimes I like to use words out of contents
Darkzombies
13
Years of Service
User Offline
Joined: 25th Dec 2010
Location: In multiple tabs, most likely youtube.
Posted: 14th Oct 2011 19:32
Oh... well I edited my other post.. can you can look at that please?

"Insert funny coding-related joke here"
zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 14th Oct 2011 22:09 Edited at: 14th Oct 2011 22:17
@Darkzombies,, I wasn't trying to bash you. And I appologize if my post came off that way. When I recommended tutorials, I didn't mean watch them... but pull apart the code,, play with them, and get a solid foundation on the principles. If you get that out of the way now, your enjoyment of the product will be more pleasant than painful.

As for your issues. You need to do some key handling. There are some good snippets on the snippets board that may help you. But generally...

- You need to check for multiple keypresses, and handle that accordingly. For some designs you may need to treat a user holding the up AND right arrow keys together differently than performing the upkey() code and the rightkey() code.

- You may want to prevent anything from happening if opposite direction keys are held like "up" AND "down", or "right" AND "left". Especially "left" AND "right" as that code is mirroring the sprite and it will certainly look glitchy!

- If you are truly limiting movements to only 4 directions then the simplest way for you to handle it, is to have an if..else...endif rather than your multiple if's structure you currently have. If you will need simultaneous keys like "up" AND "right" that suggestion will not work.

- If I have time, I'll try to work on you code later. In the mean time you should look up some codeon keystate handlers in the snippets board,, the basic upkey()=1 stuff is ok for quick prototyping purposes... but it usually falls short of what most games need.

As for the inversion,, I haven't looked over all the new code yet, but I would gather that in moving right you would want to "+" movespeed to your x coordinate. And moving left you would want to "-". I'll have to look at your full source to see if my assumption on quick glance is correct?

Your signature has been erased by a mod please reduce it to 600 x 120.
Darkzombies
13
Years of Service
User Offline
Joined: 25th Dec 2010
Location: In multiple tabs, most likely youtube.
Posted: 15th Oct 2011 00:32 Edited at: 15th Oct 2011 00:40
Lol... its so funny cause I did that, then remembered the post...

so here ya go, I did it by myself!



Now, *Dramatic music plays* TO ANIMATION!! (Once I get art done )

EDIT: Ok, so this works, but occasionally it will glitch out and not mirror the sprite. (I can actually give you the temp image if you want to test it, its attached)



"Insert funny coding-related joke here"

Attachments

Login to view attachments
zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 15th Oct 2011 01:19 Edited at: 15th Oct 2011 01:42
* I took out a lot of unecessary condition checks.

* I eliminated the need for the skip: labels and their corresponding goto's inside the if conditions.

* The logic condition checks worked out easier by evaluating the opposite condition. So I changed them. This was made possible by breaking up the x and y directions described below.

* I removed player.direction and replaced it with player.directionx and player.directiony.

The reason: The directions had to be separated because the up and down movement would over-write the old left and right direction; which were the directions you needed to have to determinn whether or not to mirror the sprite. That decision needed to be made regardless of what the sprite was doing in the vertical direction.

*(Note): I probably could work out a better scheme to handle the directions, but I think if you compare the old code to the new, you will be able to see what was going on better than if I had completely changed the scheme.

**: I was unsure if the sprite needed to flip vertically for up and down, so I left that alone.



Your signature has been erased by a mod please reduce it to 600 x 120.
Darkzombies
13
Years of Service
User Offline
Joined: 25th Dec 2010
Location: In multiple tabs, most likely youtube.
Posted: 15th Oct 2011 01:40
Much better, I didnt know up/down overrided right/left, oh well it worked, besides one thing, if you initially go right the animation gets screwed up. Ill experiment, I can probally fix pretty easy.

"Insert funny coding-related joke here"
zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 15th Oct 2011 01:49
Quote: "I didnt know up/down overrided right/lef"

It was because all directions were updating player.direction. So the sprite mirror problem would happen when you went moved on diagonals or at times if you went up OR down, and then changed the horizontal direction compared to the previous horizontal direction. That's the best I can describe it.

Another possible solution to the issue would have been to create an old_horiz_direction variable and use it to store the last known horizontal direction. Then use that variable to do the checks in the left or right input states. So you could try that if breaking up the directions causes you grief later on.

Your signature has been erased by a mod please reduce it to 600 x 120.
Darkzombies
13
Years of Service
User Offline
Joined: 25th Dec 2010
Location: In multiple tabs, most likely youtube.
Posted: 15th Oct 2011 02:29
Ok. So now I added a thing to past trees along the right side of the screen, and as you know by now, I fail at everything.



Oh yeah, and the difficulty's were giving me weird problems like "declaration name '+' is not valid"
so I remmed em out.

"Insert funny coding-related joke here"
zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 15th Oct 2011 04:21 Edited at: 15th Oct 2011 17:16
It's the fundamentals that are haunting you.

If you are going to assign a value to a global variable, that value cannot be a mathematical expression like (5 + 7), it must be an immediate value like (12) or a variable that has been set.

This will not compile


This will have compile and work


This is the safer method



I found a lot of methods that will compile but don't initialize the variable as expected... such as:



==============


The other issue you had was in duplicating sprite numbers. You can't start trees(x).id at 1, because the player already uses that sprite number. So I added 1 to it


Your signature has been erased by a mod please reduce it to 600 x 120.
Darkzombies
13
Years of Service
User Offline
Joined: 25th Dec 2010
Location: In multiple tabs, most likely youtube.
Posted: 15th Oct 2011 04:54 Edited at: 15th Oct 2011 05:08
Oh, ok, well even before you posted I fixed everything but the trees, I didnt think the player counted because it was a different thing (player.id instead of trees(x).id)

But anyways, if I did anything inneficiently, tell me.



Im fixing the trees atm.

EDIT: Ok, so theres only 1 tree...



Also, are there any good AI tutorials out there, I know how to do the actual AI(Randomize timer()/rnd(a #)) just not movement, (Except maybe like back and forth, or move with the player.)
Cause thats most likely what ill be doing next, unless someone wants to do some animations for me lol.

"Insert funny coding-related joke here"
zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 15th Oct 2011 05:12 Edited at: 15th Oct 2011 05:16
btw, Actually the decleration issues were less about knowing the fundamentals and more about experience. I'm not sure that I ever came across some of the results I was getting, and some of my trials suprised me. Those types of things I like to call quirks.

Quote: "Also, are there any good AI tutorials out there, I know how to do the actual AI(Randomize timer()/rnd(a #)) just not movement, (Except maybe like back and forth, or move with the player.)
Cause thats most likely what ill be doing next, unless someone wants to do some animations for me lol."


What type of AI are you looking for?

Your signature has been erased by a mod please reduce it to 600 x 120.
Darkzombies
13
Years of Service
User Offline
Joined: 25th Dec 2010
Location: In multiple tabs, most likely youtube.
Posted: 15th Oct 2011 05:58 Edited at: 15th Oct 2011 19:55
Just wandering around, maybe AI that just hobbles towards you, or smart AI who avoids stuff or anything like that. (Actually all lol)

Ok, also, do I have to increase the value of the .id? Just look at this for me please.



also this.



Also, do you know anyone who can do art for the game?
at lease some simple animations so I can work on my animation?

EDIT: Ok, so I implemented attacking and a little animation, but it freezes when I press the attack key ("j")

Also, enemies are just spawning everywhere constantly, going over theyre array limit, and then deleting other enemies.



if yah need the images, one is in a higher post somewhere, and heres the attacking one. (ATTACHED)

"Insert funny coding-related joke here"

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-11-24 01:24:33
Your offset time is: 2024-11-24 01:24:33