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 / why doesn't this function work?

Author
Message
mmmm_
19
Years of Service
User Offline
Joined: 31st Aug 2005
Location:
Posted: 1st Sep 2005 03:19
when I put this in my program just as standard code it works fine but when I put it in a function, it dosn't do anything.

it should, each time it is used, make a falling box randomly appear in a user-defined area.


count is the frame count, countv# is the frame you wish it to create the box on, boxwidth is the box's width, boxarea and boxmultiplier determine the area where the box will be created.

I have never realy programed before and functions are new to me, does anyone know what I am doing wrong???


Thanks
indi
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Earth, Brisbane, Australia
Posted: 1st Sep 2005 03:55
Error obtaining Source Code in the source button

post the source into your post but wrap it with

[ c o d e ] your code [ / c o d e ]

remove the spaces in the code tags for usage.



without seeing your code

if your function is updating something it Might require a sync command.
however too many sync commands might degrade performance in the main loop
depending on how your games program flow is constructed.


eg:

function showscore(Score)
text 10,10,STR$(Score)
sync
endfunction


you can write a condition to check if the score has changed and then run the function.
this might improve the functions usage in your programs loop instead of being run every loop,its only called when required.
you could write a condition using an if statement to say if the current score is higher then the older score then run the function
eg:

main loop psuedo code

Score = OldScore

rem update showscore condition
if OldScore < Score
showscore(Score)
endif

im a bit rusty today so theres bound to be a mini bug in it somehwhere, but the theory should be ok.

If no-one gives your an answer to a question you have asked, consider:- Is your question clear.- Did you ask nicely.- Are you showing any effort to solve the problem yourself &#63743;
mmmm_
19
Years of Service
User Offline
Joined: 31st Aug 2005
Location:
Posted: 1st Sep 2005 04:09
sorry... the code went like this:

function makeabox(countv#,boxwidth,boxarea,boxmultiplier)

if count = countv# then make object box countv#,5,20,boxwidth
if count = countv# then position object countv#,0,400,rnd(boxarea)*boxmultiplyer - 130
if count > countv# then move object down countv#,1
if count > countv# then if object collision (countv#,109)>0 then position object countv#,Box102POSX#,Box102POSY#+0.00001,Box102POSZ#
if count > countv# then Box102POSX# = object position x (countv#)
if count > countv# then Box102POSY# = object position y (countv#)
if count > countv# then Box102POSZ# = object position z (countv#)

endfunction
mmmm_
19
Years of Service
User Offline
Joined: 31st Aug 2005
Location:
Posted: 1st Sep 2005 04:11
sorry... the code goes like this


John H
Retired Moderator
22
Years of Service
User Offline
Joined: 14th Oct 2002
Location: Burlington, VT
Posted: 1st Sep 2005 04:21
Are you sure your looking at wherever the object is placed?

Off Subject: Indi!! YOUR ALIVE!!!


Click here to join our forums and get updates on game progress sooner!
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 1st Sep 2005 04:49
Take a look at the functions tutorial here:

http://www.computechtenerife.com/DB/tutorials.htm

It should help.

You supplied the function, but what error do you get? What call do you use? Do the parameters match?

I think once you have read the tutorial, you will probably know what the answer to your problem is...

TDK_Man

SimSmall
20
Years of Service
User Offline
Joined: 7th Aug 2004
Location: United Kingdom
Posted: 1st Sep 2005 10:14
when I had problems with functions I just replaced them all with subs -- obviously I can't say exactly how it'd translate but that ma be something you want to try...

...maybe one day I'll finish a project
mmmm_
19
Years of Service
User Offline
Joined: 31st Aug 2005
Location:
Posted: 4th Sep 2005 12:06
OK thanks, I just did it a different way in the end. - still don't know what I was doing wrong though
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 6th Sep 2005 03:54
Quote: "still don't know what I was doing wrong though"


You weren't using the function correctly. That's why I gave you a link to a tutorial which would explain them to you.

If you don't know how to do something in DB, don't just 'do it another way', find out how to do it properly!

In your function header, you had the variables countv#, boxwidth, boxarea and boxmultiplier.

Inside the function, you were using:

if count

Count is a local variable and didn't exist, so NONE of those lines would have been true and none of the code after the Then's would have been executed.

This would have been clear to you, had you read that tutorial. As it is, the next time you need to use a function, you will be just as lost!

TDK_Man

Login to post a reply

Server time is: 2024-11-27 18:46:56
Your offset time is: 2024-11-27 18:46:56