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 / What is wrong with the code

Author
Message
Slooper
21
Years of Service
User Offline
Joined: 13th Feb 2003
Location: Sweden
Posted: 14th Feb 2003 01:08
okay I am a newbie never seen programming code before but I have started now and wonder what is wrong with this code when I push the buttons the program only turns off

Rem Project: first game
Rem Created: 2003-02-04 12:12:29

Rem ***** huvud fil *****

hide mouse

rem load pic-files


rem placing the camera
make camera 1
position camera 1,0,0,0
color backdrop 1,RGB(0,0,0)
rem make the player
make object box 1,10,2,2
color object 1,RGB(255,255,0)
position object 1,0,-25,50
rem make ball
make object sphere 2,2
color object 2,RGB(0,255,0)
position object 2,0,-23,50

rem build the level
make object cube 3, 50
color object 3,RGB(255,0,0)
position object 3,0,0,0
rem lights
make light 1
make light 2
make light 3
color light 1,RGB(0,255,64)
color light 2,RGB(255,0,128)
color light 3,RGB(0,255,255)
position light 1,0,50,0
position light 2,0,100,0
position light 3,0,70,50

rem make the object move
if leftkey()=1 then move object left 1,+50
if rightkey()=1 then move object right 1,+50

suspend for key
Hockey07
21
Years of Service
User Offline
Joined: 18th Dec 2002
Location: United States
Posted: 14th Feb 2003 01:13
I dont know if your whole code got posted here, but at the beginning adding the code

SYNC ON

and at the very end of your code and stuff type SYNC

adding a sync will refresh the screen after the button is pushed so it shouldnt leave now..

Current Project: Dark Wars
166 lines of code so far
http://hometown.aol.com/Hockeycow07/rebel.html - The official ReBel Games website!
Slooper
21
Years of Service
User Offline
Joined: 13th Feb 2003
Location: Sweden
Posted: 14th Feb 2003 01:25


this maby gets it better to understand this is the whole code so far, the idea is to make a game likely the old "don´t know the name" where you have a plate and shoting a ball to take down the cubes and rewind the ball again when it is falling down... what is wrong it can´t move

The Darthster
22
Years of Service
User Offline
Joined: 25th Sep 2002
Location: United Kingdom
Posted: 14th Feb 2003 01:37
What your code does at the moment is not loop at all. You load up all the media, and then as soon as you've done that you check to see if either of the arrow keys you want are pressed. If they are, it moves the object. Then the command 'suspend for key' is used, which stops the program running until a key is pressed. After that, the program just ends, the screen doesn't update or anything.

You need a main loop, otherwise it won't work. A main loop is a do...loop command, with all the code to make the game work inside. It runs repeatedly throughout the game, so you can move your objects and run various other pieces of code repeatedly.

First you load up all the media, like you have done so.

Then you start the main loop

do

Inside the loop, you code what is going to happen each frame. You're trying to get the object to move left and right when you press the arrow keys, so you put that code inside the loop.

if leftkey()=1 then move object left 1,50
if rightkey()=1 then move object right 1,50

Then, when you've done everything you want to do that frame, use sync to draw it to the screen and loop around again. Your code should look like this:



Now the program will exit if you press the escape key by default, but otherwise will keep running, checking for keypresses and updating the objects every frame.

Once I was but the learner,
now, I am the Master.
John H
Retired Moderator
22
Years of Service
User Offline
Joined: 14th Oct 2002
Location: Burlington, VT
Posted: 14th Feb 2003 03:10
Beat me to it was doing homework Yep, dont use suspend for key

RPGamer

Current - RPG: Eternal Destiny : Help Wanted!
http://www.halbrosproductions.netfirms.com
Dont ask those questions! Read the help files lazy!
Slooper
21
Years of Service
User Offline
Joined: 13th Feb 2003
Location: Sweden
Posted: 17th Feb 2003 12:36
okay thanx for the help guys

Slooper
21
Years of Service
User Offline
Joined: 13th Feb 2003
Location: Sweden
Posted: 17th Feb 2003 18:45
Okay now the code work I think exepct for one thing, the screen is black when I use the "sync on" command what should I do
xmen
21
Years of Service
User Offline
Joined: 27th Jan 2003
Location:
Posted: 17th Feb 2003 19:12
try this

rem make the object move

do
if leftkey()=1 then move object left 1,+50
if rightkey()=1 then move object right 1,+50
sync
loop
`sync
Slooper
21
Years of Service
User Offline
Joined: 13th Feb 2003
Location: Sweden
Posted: 17th Feb 2003 22:53
yes that works but the object only shows upp when it is at the given start location. test the code and see for yourself
Flas_Coder
21
Years of Service
User Offline
Joined: 4th Feb 2003
Location: United Kingdom
Posted: 17th Feb 2003 23:05
What I have found about your code is that you have put -

if leftkey()=1 then move object left 1,50 <--

When i used you code, Object 1 would move to fast, So when you pressed either left-right key the object moved off the screen, I think what you should do is to change the control object code to this -



As you can see I have change the number 50 to 1.5 -

This should then only move the object very slowly because the object will move the object 1.5 instead in 50 -

I hope that this helps, Good luck anyway -

Did i just say that?
Slooper
21
Years of Service
User Offline
Joined: 13th Feb 2003
Location: Sweden
Posted: 18th Feb 2003 12:52
okay so the

if leftkey()=1 then move object left 1,50 <--

is not the speed, is it how many steps it moves at time or something like that?

Login to post a reply

Server time is: 2024-11-24 01:28:59
Your offset time is: 2024-11-24 01:28:59