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 Professional Discussion / Character coordinates

Author
Message
Silence
13
Years of Service
User Offline
Joined: 14th Oct 2012
Location:
Posted: 18th Mar 2013 15:14
How can something be printed if the character coordinates are specific?

So say if the character's coordinates are 650,10,650 how can I make a code that says something like this



To make myself clear that way no people have a hard time understanding, I want something to print on the screen as soon as someone is in the correct coordinates of the game and as soon as you leave from those coordinates it dissapears
Sergey K
22
Years of Service
User Offline
Joined: 4th Jan 2004
Location:
Posted: 18th Mar 2013 15:37
here are few ways to do that:
1) create a hiden object on the screen, so.
if Obj Collision(HIdenObj,Player)=1 then center text 300,300,"Press B"

2) you always can use the Val() command to convert "Object position x()" to an integer (cuz Obj Position X is FLOAT)
if val(Object position x(1) = 640) then center text...

3) or you can use between values.. X: between 10 to 30
if Object position x(1)=>10 and Object position x(1) <= 30 then center text...

Advanced Updater for your games!
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 18th Mar 2013 16:38
What type of game is this?

If it is something with fixed step movement then ignore my post.

If you are using a third person / first person engine with free movement you shouldn't really be dealing with character locations like that. Too mathematical for what it is worth.

Option 1 in Sergey K's recommendation is the one to use; you can also search for distance checking and Matrix1 zones for additional methods.

This is where a level editor helps you to reduce code; you could have zones put in place in a 3D editor and use your chosen collision method to test the location of the player with a few lines of code.

Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 19th Mar 2013 00:05
Quote: "you always can use the Val() command to convert "Object position x()" to an integer (cuz Obj Position X is FLOAT)"

Why not just use int?

Even using integers, it's unlikely your character would match up perfectly to the coordinate you want. What you should do is make a hot spot or zone. And if you plan on having more than a single trigger zone, start using arrays.




"You're all wrong. You're all idiots." ~Fluffy Rabbit
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 19th Mar 2013 00:42
Indeed, Val converts strings to numbers; Int converts floats to integers. He must of got them mixed up.

Derek Darkly
14
Years of Service
User Offline
Joined: 22nd Sep 2011
Location: Whats Our Vector, Victor?
Posted: 19th Mar 2013 16:49 Edited at: 19th Mar 2013 16:50
You can check the distance between your player and the desired hot-spot coordinates:



(There are more efficient ways of doing this, but this will work.)

D.D.
Silence
13
Years of Service
User Offline
Joined: 14th Oct 2012
Location:
Posted: 20th Mar 2013 00:43
Thank you all I got it to work. But I have one more question.

The quote "Press B" will actually be changed into an Order of Operations question. What troubles me is that everytime I start the game the equations need to be different. I need at least 10-15 questions so it changes everytime I start the game and come into contact with the object.

How can I do this?
Sergey K
22
Years of Service
User Offline
Joined: 4th Jan 2004
Location:
Posted: 20th Mar 2013 07:26 Edited at: 20th Mar 2013 07:29
in this case, the best way, you will have to try the Arrays.
for example..




note that i used Inkey$() function to check for a key press.
if you want to use more advanced system, you try scancode() instead.
it will work on Esc/Return keys too.

Advanced Updater for your games!
Silence
13
Years of Service
User Offline
Joined: 14th Oct 2012
Location:
Posted: 21st Mar 2013 03:33
I tried to do something similar but the problem is that it's not even registering. Before whenever I came into collision with the object the words printed on the screen just fine and when you walked away from collision it would disappear.

This is what I did



The problem is that the words dont even show up so I cant tell if it works or not. Will this even work what I'm doing?
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 21st Mar 2013 10:22
Just a polite question. Why are you not using a ready made solution for reference?

Silence
13
Years of Service
User Offline
Joined: 14th Oct 2012
Location:
Posted: 21st Mar 2013 18:10
Because I'd rather stick to something I know rather than waste time and try and learn a new piece of code that I would most likely not succeed with because of my limited knowledge. This is a project that's due very soon.

In all honesty I am quite upset when it comes to this forum at times.
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 21st Mar 2013 19:24 Edited at: 21st Mar 2013 19:24
I am just asking because you could copy and paste what you need into your program and finish it; a bit like putting clipart into Microsoft Word instead of hand drawing it... It's good practice, great programmers copy and paste. Anyway happy coding.

Silence
13
Years of Service
User Offline
Joined: 14th Oct 2012
Location:
Posted: 21st Mar 2013 22:35 Edited at: 21st Mar 2013 22:52
The thing is what if the code handed to me doesnt work? Then that's time wasted of having someone trying to explain it in a way that's too advanced for a beginner. So whenever I ask a question, I would just like it to be answered and not have someone go off on some tangent and me not understand what they're trying to tell me.

And as it just so happens I have fixed my problem. So thank you.
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 22nd Mar 2013 01:48 Edited at: 22nd Mar 2013 01:58
Great to hear.

I am guess you may have had bad experiences from using ready made code because you asked what if coded handed to you doesn't work; but I wouldn't have recommended that you use code that doesn't work; that wouldn't be very helpful. Code that doesn't work was probably created by someone inexperienced.

A good technique is to not think too specifically when problem solving; gotta focus on the big picture; use more open questions and post the whole program. For example; if you ask how to display text when a character is at a certain position, you end up spending a number of days waiting for 5 or 10 people to get spare time to read your post, pay the rent, cook dinner, play COD, watch Oprah then spend some of their limited time figuring out a solution for you. Then after all that, 2 days later you end up learning how to display text when a character is at the position.... But if you asked; how would you create a user interface for this program I made, I need text to display when the character is in a certain position and post the whole program; over the course of the day you would receive 10 times more valuable help, in addition you would also get further tips on the program as a whole; because A you posted the whole program so we have more to think with; and B, the question posed is the big picture, when we get the spare time to help out, we are answering a more useful question far more beneficial for you.

Anyway, in good time you will understand why I made my comments

Silence
13
Years of Service
User Offline
Joined: 14th Oct 2012
Location:
Posted: 22nd Mar 2013 02:14
Sounds reasonable enough. Can you help me with one more thing then?

I have an input code that is malfunctioning. When the player presses the Enter key it takes them to a new section to input their own answer. Problem is it's not working correctly. I tried numerous ways to get it to work and I bring it to you



What happens when I use this is that Darkbasic considers every answer wrong and you cant win the game. I really have no clue what to do here.
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 22nd Mar 2013 03:34
Boy am I glad you almost posted all of the code; the problems are more easy to see when you can look at them. Unfortunately it is 2:30 am in the morning and I should really go to bed;

for now, be sure to make sure the input statement assigns the value to the variable 'lock$'; currently it is assigning to the variable 'lock' without the dollar sign, which is not only a different variable, but a non string variable which is not fit for an input command. And I am sure there is a missing EndIf command there; is this the code that actually compiled?

There is more, but my head is falling of my neck; hopefully someone on the other side of the planet who has sunlight can point out the issues.

Post the rest of the code, there might be more problems unseen; I think it might be good for me to add some comments directly into the source code explaining some tips

Later

ShellfishGames
13
Years of Service
User Offline
Joined: 6th Feb 2013
Location:
Posted: 22nd Mar 2013 08:53 Edited at: 22nd Mar 2013 08:55
Just to get that out of the way, the code indentation should actually look somewhat like this:


(Note: If you write [ code lang=dbp] (without the first space) inside your opening code-tag when posting here, the code will be highlighted accordingly)
Most importantly the 'if lock$="24"' and its endif 8 lines below should be on the same level, and everything in between one tab to the right. This way you avoid confusion as experienced by Chris Tate regarding the correct number and order of selection- and nesting-operations.

As to why the code doesn't work properly, as Christ mentioned, the existence of two different variables lock$ and lock might be the primary problem here. On top of that your block of if-statements regarding the confirm$-variable doesn't look good. What if the user inputs an empty string, any other letter than "y" or "n" or even "Y" (note that upper and lower case are actually different values, so confirm$ = "y" would return 'false')? In this case nothing will happen. You should go with if-else-endif here (and possibly use the lower$()-function to make sure "y" and "Y" are handled equally):



Silence
13
Years of Service
User Offline
Joined: 14th Oct 2012
Location:
Posted: 22nd Mar 2013 15:53
Thank you all for your patience. I got it to work.

Login to post a reply

Server time is: 2026-07-07 20:23:02
Your offset time is: 2026-07-07 20:23:02