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 / Variable in text do not change!

Author
Message
Dritt
18
Years of Service
User Offline
Joined: 10th Jan 2006
Location:
Posted: 18th Apr 2007 12:36
Hello folks.

I was wondering if you could help me out a little bit.

Ok, so i have this variable called, player credit = 100. And to display it on the screen i have, Text 500,500, "Player Credit, " + player_credit.

The problem is that the number will not decreas or increase. Its just static. But when i print the player_credit on the creen it works, not with text command.

The same with date and time, its just static.

How do i get it to work?
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 18th Apr 2007 16:56
Numeric variable will only print using the PRINT command. So you can use:



With the TEXT command, you cannot do this - you have to convert the numeric variable to a string with STR$() first. This makes it:



TDK_Man

Dritt
18
Years of Service
User Offline
Joined: 10th Jan 2006
Location:
Posted: 18th Apr 2007 17:09
Thanks for a quick replay!

Yes, i have tried that before. Did it again but it dousent work.

For the decrease and increase part i have, player_credit=player_credit -10. This should be correct right?

Any other suggestions.
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 18th Apr 2007 17:55
Quote: "Yes, i have tried that before. Did it again but it dousent work."


In that case, the only thing it can be is where the command is used - and you do need to use STR$() and the text command as shown above btw.

As you've not supplied any code to look at, it's impossible to be certain, but it sounds like you might be trying to print a non-local variable in a function - or a local variable outside of the function it was created.

If this is the case, simply define a global variable.

Quote: "For the decrease and increase part i have, player_credit=player_credit -10. This should be correct right?"


Personally, I prefer

Dec player_credit,10

but they do the same thing. However the local/global aspect is the same.

If you create a function which contains A=100, then using INC A outside of the function will be incrementing a different A to the one inside the function. You would need to make A global to make this work as you want it to.

TDK_Man

Dritt
18
Years of Service
User Offline
Joined: 10th Jan 2006
Location:
Posted: 18th Apr 2007 23:34
Hmm...how do i do that? I dont even know whats INC...

Would it be to much trouble to make the code for me?

Or explain wich commands to use, and in wich order.

If its not to much trouble of course?

How does the rest of you do it, every game has some kind of scoring, health, life and ammo system.
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 19th Apr 2007 00:16
Quote: "Hmm...how do i do that? I dont even know whats INC..."


Inc and Dec stand for INCrement and DECrement. You already said you used player_credit = player_credit -10. Dec player_credit,10 is another way to do the same thing.

Inc player_credit,10 adds 10 instead of taking 10 away.

Quote: "Would it be to much trouble to make the code for me?"


Yes it would.

Only joking!

I don't like doing that because you won't learn anything other than how to copy and paste code.

I'm quite happy to tell you what to do - then you go away and learn how to do it yourself.

Anyway, at the start of your program you just put:

Global VariableName

You just replace 'VariableName' with the name of the variable you want to be global. It is then available both inside and outside of functions and procedures.

Check out the following link:

http://forum.thegamecreators.com/?m=forum_view&t=99497&b=10

The beginners tutorials (1 to 4) might be worth you reading (local/global variables are explained in Part II). Functions have their own tutorial (number 6).

TDK_Man

Dritt
18
Years of Service
User Offline
Joined: 10th Jan 2006
Location:
Posted: 19th Apr 2007 00:41
Thank you very much for the link.

Login to post a reply

Server time is: 2024-11-25 19:34:50
Your offset time is: 2024-11-25 19:34:50