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.

DarkBASIC Discussion / A little puzzled here...

Author
Message
Xenocythe
19
Years of Service
User Offline
Joined: 26th May 2005
Location: You Essay.
Posted: 24th Jul 2005 04:35
How do I make it so two 'loops' can run at the same time, so when I change a loop, the things in the loop I want to stay dont have to be written in the next loop.
Or isn't that what functions are for or something?
Underworld 1020
21
Years of Service
User Offline
Joined: 2nd Mar 2004
Location: NY, USA
Posted: 24th Jul 2005 05:05 Edited at: 24th Jul 2005 05:07
You mean like a subroutine...like this:


Thats just a basic example, but that should give you an idea of what I mean. The Msg1 and Msg2 are called "labels", the GoSub command is used to make the program "jump" to that label and run the code that is below it. The Return command makes the program jump back to where it came from. To make a label just write something like Msg1 and then put a : after it, and that will make it a label. Let me know if you get confused.

EDIT: By the way before you start using functions learn how to do labels and stuff first, and then functions will make more sense.

Xenocythe
19
Years of Service
User Offline
Joined: 26th May 2005
Location: You Essay.
Posted: 24th Jul 2005 05:44
Hahaha... sorry... but I'm not the first class newb.

I know what all this stuff is, lol, but I would have to add all the gosubs in the other loop... well it's better then anything.

Thanks man, but for the heads up, dont mistake me for that much of a newb
Zotoaster
20
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 24th Jul 2005 07:11
if your gonna have two loops that run exactly the time then why dont you just use one loop?

Your signature has been erased by a mod because it's larger than 600x120...
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 24th Jul 2005 11:47
What exactly are you trying to do? Post some code.
Xenocythe
19
Years of Service
User Offline
Joined: 26th May 2005
Location: You Essay.
Posted: 24th Jul 2005 13:07 Edited at: 24th Jul 2005 13:10
Sorry, but its too long for a snippet. It's the beginning of my Action FPS rpg...

But this is what I'm trying to do:
Im trying to make it so in the loop, where you can move the character, its in Third Persons View, behind the Character and following the character. I have it like this, and when you hold control key you go into First Persons View while holding. I want it so you to go into First person view when you press control key, and don't have to hold it down. And then when you press control key again, it goes back to the Third Persons View. While this is happening, the game loop is happening (with shooting and everything).

This is a basic example (NOT intended to be compiled in darkbasic... just a read-through) :



As you can see, this is what makes it so you have to hold control to go into first persons view... I want to be able to only have to press it once!
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 24th Jul 2005 17:47 Edited at: 24th Jul 2005 17:55
How about using a timer? This may toggle Cam too quick for your code (or too slow) so change the "250" to a number that works good for your code.

Hope this helps.

NanoBrain
20
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Portland, OR
Posted: 24th Jul 2005 18:46 Edited at: 24th Jul 2005 19:06
Xenocythe,

There is a simple trick to make this work. Use a single variable to technically switch the views back and forth. The code for the third-person viewing, and the code for the first-person veiwing should each be grouped seperately into two IF statements. The variable will be checked against for true or false of its value. Below is the code without the ability to switch back and forth.

Example:


Now, we must be able to switch the variable, essentially switching the view type.

Example:


The above code will effectively switch the variable, but uncontrollably. To clarify, if the key is held down through 60 program loops, it will switch the view 60 times, in the blink of an eye. However, we only want the view to switch when press the key, only after it having been not pressed the moments before. Let us make a keypress controller. Note, the code used to do so should not be placed in either IF statement, to keep from typing the code into both statements.

Example:


The above method simply only allows the view to be switched once per keypress, though the key may be held. The view can only be switched again, if so-be that the key is first let off of, and then pressed again. Many programs, ones that involve user input from the keyboard, use this method.


+NanoBrain+

Login to post a reply

Server time is: 2025-05-22 12:43:56
Your offset time is: 2025-05-22 12:43:56