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

Author
Message
bjornli_90
11
Years of Service
User Offline
Joined: 1st Dec 2013
Location: Norway
Posted: 24th Mar 2015 21:27
I am trying to write a simple function that determines a new valueto identify a string, every x frames.

I am relatively new to programming, but I think I'm able to master the basics and some more..

I can't seem to get it working Please take a look and tell me what I am doing wrong..

with this code it seems to be working correctly at the exact frame specified, but not every frame until next change, which is my intention. Sync rate is slowed down to easily follow the changes.

Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 25th Mar 2015 11:57
It would help us to help you if you told us what values you are getting and what you expect.

In the meantime what's the point of this bit of code?



That just seems to be a roundabout way of saying:



Also, it would be good practice, and probably essential, to declare variables such as value as global - because they are used both inside and outside the function chose(). If you don't do that then the compiler thinks they are two different values and the one used inside the function will always be zero. I guess you want them to be the same variable.

For the same reason, the variable hand will be zero most iterations unless you declare that as global in the main program as well. Every time you call a function any local variables used in it will be initialised to zero. If you want values to persist between calls then they need to be declared as global. For example, in your main program you could replace



by



However, I'm not sure what exactly your code is supposed to be doing.

There may be other things you need to change as well.



Powered by Free Banners
bjornli_90
11
Years of Service
User Offline
Joined: 1st Dec 2013
Location: Norway
Posted: 25th Mar 2015 12:27 Edited at: 25th Mar 2015 18:14
Thanks for the reply, I had forgotten about the local/global thing.
I may be able to rewrite it so that it works now.
That bit of code is supposed to change the variable 'value' with 'newvalue' , but only if it is different from what it previous was..
I now see that I might not need it in the code at all..

*EDIT* :
I have now been rewriting the first lines of code from my project, global/local values was the problem.
This is just a small part of a larger project, but i like to separate and test out different aspects and make sure it works before implementing changes to the actual project

Thanks for the help
Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 26th Mar 2015 10:57
You're welcome.



Powered by Free Banners

Login to post a reply

Server time is: 2025-05-11 05:26:18
Your offset time is: 2025-05-11 05:26:18