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 / Functions not working

Author
Message
Indian Homie G
20
Years of Service
User Offline
Joined: 23rd Jan 2004
Location: San Jose, CA
Posted: 3rd Jul 2004 06:03
I just added a function to my program but its not working, the program just stops. heres my code. its pretty self-explanatory thats why i didnt explain much.


you can ujst run it, theres no models.
Thanks!
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 3rd Jul 2004 06:43
add () right after the function name


* DBP_NETLIB_v1.4.3 - July, 2004 * Click Logo
Indian Homie G
20
Years of Service
User Offline
Joined: 23rd Jan 2004
Location: San Jose, CA
Posted: 3rd Jul 2004 06:50
now looks like this:
function camerachange()

same thing happens...did you try it out? thanks
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 3rd Jul 2004 07:33
oh oops

Take the function out of the loop and put it at the end of your code


* DBP_NETLIB_v1.4.3 - July, 2004 * Click Logo
Indian Homie G
20
Years of Service
User Offline
Joined: 23rd Jan 2004
Location: San Jose, CA
Posted: 3rd Jul 2004 07:37 Edited at: 3rd Jul 2004 08:25
okay never mind i fixed the problem.
so now when i press the spacebar, the view is toggled, and the camera is closer to the player. now i want to toggle it back...i knew exactly how to do it, and it just slipped my mind anyone got any ideas? thanks
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 3rd Jul 2004 08:26
This code runs although I don't know if its doing what you expected.
As far as the problem, you have a variable and a function named the same: camerachange()

I renamed the variable to VARcamerachange




* DBP_NETLIB_v1.4.3 - July, 2004 * Click Logo
Indian Homie G
20
Years of Service
User Offline
Joined: 23rd Jan 2004
Location: San Jose, CA
Posted: 3rd Jul 2004 08:31 Edited at: 3rd Jul 2004 08:37
i tried that, but it doesnt do anything ?

this my my code right now
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 3rd Jul 2004 09:23
copy my code and paste it into your project
I looked at yours and it doesnt have the changes


* DBP_NETLIB_v1.4.3 - July, 2004 * Click Logo
Indian Homie G
20
Years of Service
User Offline
Joined: 23rd Jan 2004
Location: San Jose, CA
Posted: 3rd Jul 2004 09:50
no i mean i tried your code, it didnt do anything when i pasted it into mine, so i tried some other stuff
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 3rd Jul 2004 10:35
well it runs here.
not sure what to say


* DBP_NETLIB_v1.4.3 - July, 2004 * Click Logo
Indian Homie G
20
Years of Service
User Offline
Joined: 23rd Jan 2004
Location: San Jose, CA
Posted: 3rd Jul 2004 11:05
oh well thanks anyway
Don Malone
21
Years of Service
User Offline
Joined: 27th Apr 2003
Location: Birmingham, Alabama
Posted: 6th Jul 2004 08:26 Edited at: 6th Jul 2004 08:27
Indian Homie G

The only two things that you have to remember in using functions is that the function should not be in the main loop and should not share a name with another label or variable. Cattle rustle was correct about those minor problems you had. The biggest problem is seeing it in the code. That is why alot of people start the function name with and underscore or the prefix "fun" of "f" (example your function could be named either _camerachange(),Functioncamerachange() or f_camerachange() for clarity and avoiding double use of the name.

Wasting CPU Cycles since the 286 was a hot machine.
SandraD
20
Years of Service
User Offline
Joined: 30th May 2004
Location: Down on the corner, out in the street.
Posted: 6th Jul 2004 10:26
And the functions always come after the end of main program....

Any truly great code should be indisguishable from magic.
Don Malone
21
Years of Service
User Offline
Joined: 27th Apr 2003
Location: Birmingham, Alabama
Posted: 6th Jul 2004 23:04
Did I leave that out?
Sorry for my error and thanks for the catch.

Guess that is why I am still struggling with the learning curve, that and lack of effort.

Wasting CPU Cycles since the 286 was a hot machine.
Bean
20
Years of Service
User Offline
Joined: 23rd Mar 2004
Location: Flower Mound Texas
Posted: 8th Jul 2004 01:14
CattleRustler -
Indian Homey G is correct. The code that you posted does not work the way that he wanted. If you run the code, it displays correctly but the spacebar does not function. You correctly removed the function from the body of the loop, but there is no call for the function within the loop. If you place a call to your function it works much better.
But what happens is that the spacebar changes view as long as the key is pressed. When you release the key, the field of view changes back to its former location. I don't know if this is exactly what Homie wants. I was under the impression that he was looking for a different action. I think he was wanting to press the spacebar and have the view stay. A second press of the spacebar would toggle the view to the alternate view. At any rate this is an interesting programming exercise and would be of value to many people in game programming. Got any ideas?
SandraD
20
Years of Service
User Offline
Joined: 30th May 2004
Location: Down on the corner, out in the street.
Posted: 8th Jul 2004 03:32
Good point bean... there are several that have desired to have things change at a key press and then change back, then drive themselves nuts as they attempt to create a "debounce" routine for the toggle. This would be a good tut.

Any truly great code should be indisguishable from magic.

Login to post a reply

Server time is: 2024-11-27 00:44:40
Your offset time is: 2024-11-27 00:44:40