Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Nate5700

Pages: [1]
1
QB64 Discussion / Re: XML in QB64?
« on: May 27, 2020, 01:45:04 pm »
Yeah it's what I was hoping to avoid, anyway. Probably what I already have is good enough, as long as I remember that I have to enclose the tile numbers in quotes when reading from the CSV file so that it interprets it as a single string variable. Which is easy for me to do, but I'm wanting to make the file format somewhat intuitive for others as well, there may be someone who plays my game that wants to make their own custom levels.

Here's another question while we're on the topic of parsing strings: It's something I've never really done before in BASIC. So, I'm not sure if the way I've come up with to parse a string is the best way. Here's what I've got:

Code: QB64: [Select]
  1.             WHILE MID$(tiles$, strindex%, 1) <> "," AND MID$(tiles$, strindex%, 1) <> ""
  2.                 strread$ = strread$ + MID$(tiles$, strindex%, 1)
  3.                 strindex% = strindex% + 1
  4.             WEND
  5.             strindex% = strindex% + 1
  6.             tile% = VAL(strread$)

Where "tiles$" is the string from the CSV that lists the numbers of the image tiles you want to use, and "tile%" is the extracted value that you use to actually find the tile. This bit of code definitely works, I just have this feeling that there's a better way to do it.

EDIT: Modified the code as follows so that I'm not calling MID$ three times every loop:

Code: QB64: [Select]
  1.             nextchar$ = MID$(tiles$, strindex%, 1)
  2.             WHILE nextchar$ <> "," AND nextchar$ <> ""
  3.                 strread$ = strread$ + nextchar$
  4.                 strindex% = strindex% + 1
  5.                 nextchar$ = MID$(tiles$, strindex%, 1)
  6.             WEND
  7.             strindex% = strindex% + 1
  8.             tile% = VAL(strread$)
  9.  

2
QB64 Discussion / Re: XML in QB64?
« on: May 27, 2020, 01:29:54 pm »
With LINE INPUT you'll read a full line at once.

Looking at it, it looks like LINE INPUT just reads the file line to a string variable, so to get the values out of it I'm back to trying to parse a string. I guess I could read the line from the file, PUT that line to a temporary file, and then read that with INPUT? That doesn't seem much more efficient than what I'm already doing. But maybe I'm missing something.

3
QB64 Discussion / Re: XML in QB64?
« on: May 27, 2020, 12:37:14 pm »
Thanks Fellippe, I'll take you up on your offer to help actually.

Let us know how we can assist you with any part of OPEN/INPUT stuff.

Is there any way that INPUT can detect the end of a line in a file? I didn't see anything in the wiki on that and playing with it, it looks like it just moves to the first value on the next line when it encounters the end of a line.

What I'm trying to do is write a sub that takes a line from the file that describes an object or obstacle in the game. The artwork I'm using from OpenGameArt doesn't seem to lend itself well to tiling in a logical order, so for each object I'd like to have values that describe which image tiles to use when displaying the object. Because of that, the lines for each object might not be a fixed length.

The workaround I have right now is that in the file, the last field for each line is a string, and then you put the tile numbers in that string, which keeps the line with a fixed number of values. I wrote a sub to parse the string to figure out what tiles to use, but it would seem more efficient just to grab the values from the file instead of having to parse a string.

4
QB64 Discussion / Re: XML in QB64?
« on: May 26, 2020, 11:55:03 pm »
OK so maybe I'm misunderstanding the use of C libraries in QB64. Is it that QB64 has support for certain C libraries, or they are already built in?

I found an XML library consisting of a ".c" and a ".h" file. I tried putting "DECLARE LIBRARY ".\xml_parse_lib"" into a test program and QB64 actually crashed on me every time I tried to do it. Is this a bug, something I did wrong, or is it just that this is something QB64 isn't supposed to do? You would think the program would just flag it and say "nope, can't do that" instead of crashing though.

Guess I need to find another method. XML is convenient but it certainly isn't the only way to do things. I was just hoping not to have to write something to parse strings myself, so that I can actually worry about programming a game. Oh well.

EDIT: So I did some more reading and discovered the use of OPEN and INPUT for reading files, so I can do basically what I wanted to do with the XML as comma-separated files instead. Gosh, I keep answering my own questions.

XML would still be nice as an intuitive way for a human to read the file. But not critical for what I'm doing right now.

5
QB64 Discussion / XML in QB64?
« on: May 26, 2020, 09:51:24 pm »
Hello again all,

I am thinking about the game I've started and how to design levels for it. One thing I've done that seems to work well in other languages is to use XML to describe a level to a program, and have the program "build" the level from the XML file. Is a QB64 XML library a thing? Or would I need to use a C library for this purpose?

I looked at the page on the wiki about using C libraries and I started getting a little dizzy trying to understand it. But the way I learn is by trying and doing, so I can probably figure that out. But if there's already a QB64 library I can use, let's go with that then.

Thanks in advance for any help you can provide!

6
QB64 Discussion / Re: Trouble with _KEYDOWN for a game?
« on: May 26, 2020, 06:07:44 pm »
Take a look at Task 9 in my tutorial: http://qb64sourcecode.com/Task9.html

I go over each method of keyboard input along with example programs to accompany them.

_KEYHIT has many of the same limitations as the INKEY$ command mainly being the buffered input and slow repeat rate. Not really great for games that need instant keyboard response. In order to implement _KEYHIT for fast action games you'll need to create a latching variable and then detect when the key has been released which _KEYHIT can do as well.

I'll have to give this a closer look! Funny, I actually had found your tutorial before I joined this forum and it was already open in a tab in my browser, I just hadn't read through it fully yet!

_KEYDOWN seems to definitely be working for my purposes. I changed the code so that you can use A and D for movement with RCTRL for jump and it works fine. Something about those keys with Shift seems to be funky on this keyboard, for sure.

7
QB64 Discussion / Re: Trouble with _KEYDOWN for a game?
« on: May 26, 2020, 04:56:52 pm »
Depends how you want to use them in a loop, and what you want to trap but I'd say use _KEYDOWN for detecting key combinations shift + something, or alternate or ctrl and use _KEYHIT for arrows or letters, more specific things.

I'm finding that for gaming _KEYDOWN is much more effective. When I thought _KEYDOWN was at issue with my problem I tried switching to _KEYHIT. I may not have been using that particular function properly either, but I found it to be very jerky and inconsistent on whether it detected the movement keys being pressed. For a game where the user is going to be mashing several buttons at a time, _KEYDOWN seems to be the way to go, even if you're not looking for particular keys like SHIFT, ALT, etc. At least for what I've seen so far.

It's my first time trying to do it in QB64 but this isn't my first go around at attempting to write a game. It seems like all the gaming libraries I've looked at have all had a function similar to _KEYDOWN that just detects whether the key is pressed or not, specifically for the purpose of input to the game.

8
QB64 Discussion / Re: Trouble with _KEYDOWN for a game?
« on: May 26, 2020, 01:45:00 pm »
Thanks all for the welcomes, and for the helpful links. I'm enjoying writing programs with QB64 so far, so hopefully I can be a helpful participant on the forum. QBASIC was my first exposure to programming back when I was around 10 years old, which was...*looks at watch* 26 years ago now. Wow I feel old. But because of that I was extremely excited to find out QB64 was a thing.

9
QB64 Discussion / Re: Trouble with _KEYDOWN for a game?
« on: May 26, 2020, 01:50:56 am »
After some additional searching of the forum and additional testing, I've decided this must be a hardware issue with my keyboard. If I use the left/right arrow keys with left shift, the problem goes away. Stupid laptop keyboard. I'm thinking about grabbing my USB keyboard from the other computer and trying that just to see if I can replicate the issue there.

Sigh.

Please let me know if there's something I'm missing but I'm thinking this is a mystery solved.

10
QB64 Discussion / Trouble with _KEYDOWN for a game?
« on: May 26, 2020, 12:42:02 am »
Hello all, I'm new so I'm sorry to bug you guys with a question in my first post, though I'm sure that happens a lot. I'm also sorry if this has been brought up before but I wasn't able to turn anything up on the Google.

I'm trying to use the _KEYDOWN function for input to a game. Specifically I'm trying to use the A and D keys to move left and right, and the right shift key to jump. However, for moving right, for example, I'm using "_KEYDOWN(68) OR _KEYDOWN(100)" so that the player still will move even if the user leaves CAPS LOCK turned on or if the player is trying to move and jump at the same time. Like so:

Code: QB64: [Select]
  1.     'Walk when movement keys are pressed.
  2.     IF _KEYDOWN(68) OR _KEYDOWN(100) THEN
  3.         plr.mirror = 0
  4.         IF plr.x + PLR_WALK_SPEED <= GAME_WIDTH - plr.w THEN
  5.             plr.x = plr.x + PLR_WALK_SPEED
  6.         ELSE
  7.             plr.x = GAME_WIDTH - plr.w
  8.         END IF
  9.         plr.mirror = -1
  10.         IF plr.x - PLR_WALK_SPEED >= 0 THEN
  11.             plr.x = plr.x - PLR_WALK_SPEED
  12.         ELSE
  13.             plr.x = 0
  14.         END IF
  15.     ELSE
  16.         plr.walkanim.currentframe = 0
  17.         plr.walkanim.frametime = 0
  18.     END IF

The problem is that the A or D key will "stick", that is if I'm jumping and moving right, and release the D key before releasing Shift, the game thinks the D key is still pressed and the player continues moving to the right until the D key is pressed and released again.

My first thought was this had to be a bug with the _KEYDOWN function but being that I'm new to QB64 it's more likely an error on my part, that I'm somehow not using the function properly. Can anyone help me shed some light on this? Thank you in advance for your help!

Pages: [1]