Variable++
Miscellaneous Forums/General Discussion/Variable++
Hi, I use Blitz3D and i miss a function like it is in C++ or other languages, it`s:
Intreger++ : Intreger--
Intreger+= : Intreger-=
and
Float#++ : Float#--
Float#+= : Float#-=
I hope, it wasn`t already discussed because the Search don´t use at '++' or '--'.
Can't be done, end of story.
doh! thx noel :) deleting due to head in BMAX clouds
gman: Blitz3D, not BlitzMax.
why can´t it be done @Noel Cowere
(i hope you understand me?!)
well it can't be done actually should be without added code
You could set up a function to add or subtract with the following syntax
global lives = 3
...(main loop code)
if killed = true then minus(lives,1)
if newlife = true then addition(lives,1)
(..main loop code)
function minus(newlives,num)
newlives=newlives-num
end function
function addition(newlives,num)
newlives=newlive+num
end function
You would have to be careful whcih type of integer or float you used in the funcition - as long as the variable was originally declared as a compatible variable you shouldd be okay - global allows you to use variables in functions (out side the main loop).
hope that helps.
i mean it shell "gone" into the compiler(and a variable that is 2Letters long, there don`t help any function)
Schnuff: Because it can't be done. There is no support for those operators in Blitz3D.
IPete: That code wouldn't work.
In your function, lives is a local variable and in the global scope lives is declared as well, so it just wouldn't work in a logical environment (and last I checked, B3D was one).
Ok Noel - sorry you can see where I was going though yes?
Can you quickly re-write it for me showing me how it should be please...
IPete2.
OK, if it couldn`t be done, i wil abstract me, the discusion
Pete:
Global lives% = 3
...(main loop code)
If killed = true And lives > 0 Then lives = lives - 1
If newlife = true Then lives = lives + 1
(..main loop code)
Schnuff
The equivalent can be done in functions - like the one I was trying to outline quickly for you.
@Noel yes I know you can do it that way (tut!) but Schnuff wanted a convenient way to do a similar thing didnt he?
IPete2.
What is inconvenient about writing 'lives=lives-1'? I would think that writing a whole function just to subtract n from a global variable was inconvenient.
just change all your variables to one letter :-) l=l-1
I would agree
IPete2.
stop being difficult noel...
--Mike
I'll assume that's humor.
another one of your ASSumptions huh...
;)
--Mike
Red: I believe an "H" after Ass would make it even more offensive.
go use c++
It would be nice however, and I can't believe that it would be a hard addition to make.
Take for instance this sample code I have in a program I am writing:
Brd(TeleOutLoc((Brd(xiter, yiter+1, 0)-59), 0), TeleOutLoc((Brd(xiter, yiter+1, 0)-59), 1)-1, 0) = Brd(TeleOutLoc((Brd(xiter, yiter+1, 0)-59), 0), TeleOutLoc((Brd(xiter, yiter+1, 0)-59), 1)-1, 0) + 1
it would be nice if I didn't have to type the whole dang thing twice and hope that I didn't mess up somewhere:
(Brd(TeleOutLoc((Brd(xiter, yiter+1, 0)-59), 0), TeleOutLoc((Brd(xiter, yiter+1, 0)-59), 1)-1, 0))++
shutup Wolron. :)
value=value+1 == value++
value=value-1 == value--
if basic=notgoodenough then shutup_Schnuff
go use c++
Or, rather than that drastic a change, BlitzMax. I ASSHume that gman's post was mentioning how it has capabilities like "integer :+ 1" and "float :- 1.5".
go use Blitzmax (or c++)
... u gimp.
die thread, die! :)
value=value+newvalue == value+=newvalue
value=value-newvalue == value-=newvalue
and:
Schnuff == gimp
muk, shutup and go to sleep.
why, you gimp!
IPete2: That won't work because you cannot pass by reference in Blitz. You can't pass by pointer either, except for pointers to objects, therefore, the only way to do that would be to wrap the integer variable in an object and pass the object pointer to the function.
I like the ++ and the -- usage as well..
Thanks Mark!! :)
"IPete2: That won't work because you cannot pass by reference in Blitz"
Ahh but he was using a global variable y'see!!
Anyway you're right as always, writing an increment() function is a big fat waste of time, even for globals...
++
--
good
increment()
decrement()
bad
nuff said
:D
Ahh but he was using a global variable y'see!!
Then it comes to the problem of scope. Because he used the same name as the global variable for the argument, the argument takes precedence and the global variable is not modified at all.
Ahh but he was using a global variable y'see!!
Sure, but his functions weren't. Function and variable names have been changed to protect the innocent:
Global foo = 1
increment(foo, 1)
Print foo ; prints 1, not 2!
Function increment(bar, num) ; foo's value is copied into bar
bar = bar + num ; increment our copy
End Function ; when we return, bar goes out of scope and our changes are lost
ok Gimps I have been quite long enough since I posted my rushed code yesterday:
(Good grief I was only trying to show the guy which direction to proceed with his thinking, nothing more.)
Anyways - this is what I should have posted -
Sheesh!
IPete2.
********************************
Global lives = 3
Graphics3D 1024,768,32,2
While Not KeyDown(1)
If KeyDown(200) Then
killed=True
minus(lives,1)
Else
End If
UpdateWorld
RenderWorld
Cls
Text 0,0, lives
Flip
Wend
Function minus(newlives,num)
newlives=newlives-num
lives = newlives
End Function
****************
This is working code.
Pretty stupid but it show what I was getting at.
Pretty stupid
Beyond a shadow of a doubt.
YES but it works
Whether the initial (rushed) code IPete2 posted worked or not - he was TRYING TO HELP. A concept that a certain moronic 17 year old seems to have some trouble grasping.
One set of functions per global variable? Ouch.
Trying to help when you have no idea what you're talking about can do more harm than good.
Mousey: 1) I was helping too. I've helped many people here over the past two years, and I don't think many people will disagree with that.
2) You may wish to refer to the Terms of Service you agreed to when you joined this forum:
You agree that you will uphold a standard of conduct that refrains you from personally attacking others, regardless of their beliefs and/or ideas.
I haven't done anything to warrant your attack, the only thing I've done here is provided alternatives to IPete2's method (which was bad, I don't think he'll disagree with that either).
Noel, you've got the words all wrong in your sig, it should be...
"You put your left foot in, left foot out, in out in out and shake it all about."
Please correct this...
I think this has thread has taken the long way round and reached an illogical conclusion...