Variables CLEAR

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
oryaaaaa
Addict
Addict
Posts: 825
Joined: Mon Jan 12, 2004 11:40 pm
Location: Okazaki, JAPAN

Variables CLEAR

Post by oryaaaaa »

I want to learn which variable to have initialized quickly.

Code: Select all

Global a.l, b.b, c.l, d.s, e.f, g.b=20

Start:

; .....
repeat
  ; .....

  if event=restart
    VariablesClear a,b,d,e,g
    ; a=0 : b=0 : d="" : e=0 : g=20
    goto Start
  endif
forever

It cannot be understood that the variable increases.
Cannot you do simply?

Thanks
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

it's not possible to check this in runtime,
you have to keep track of the used variables by yourself.

but this should not be that difficult,
because i think you only need a handfull of variables really resettet,
most variables you used anywhere dont need it.

what exactly do you need to do?
oh... and have a nice day.
User avatar
oryaaaaa
Addict
Addict
Posts: 825
Joined: Mon Jan 12, 2004 11:40 pm
Location: Okazaki, JAPAN

Post by oryaaaaa »

Do you have the experience of writing a long source code
spending one year or more?

Your opinion is a young person limitation.
variable input temporary or initialize?
a structure variable, 200 variables, do you clear in Big Applications ?
this restart example is one example.
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

Can you explain exactly what it is you're after.

If you need certain variables reset each time your program starts then have an init procedure that is called at the start of the program that resets them each time it is called. Don't know if this is what you are after?
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

oryaaaaa wrote:Your opinion is a young person limitation.
really unpolite. I'm disappointed. I expected much more from a japanese man.
oh... and have a nice day.
Nik
Addict
Addict
Posts: 1017
Joined: Fri May 13, 2005 11:45 pm
Location: Germany
Contact:

Post by Nik »

I think the concept of an InitFunction could realy do the trick, if the values are constant you could also use a macro which everytime it is applied to the variables sets them to the values you want them to be then you can use this at the start of the program and everywhere you want to set them to those start values again. I still don't understand what you are asking for.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

> I think the concept of an InitFunction could realy do the trick

indeed.

I don't know any programming language where some Clear_All_Variables is implemented,
you always have to write it on your own.

the easiest solution would be to restart the whole application.
oh... and have a nice day.
chris319
Enthusiast
Enthusiast
Posts: 782
Joined: Mon Oct 24, 2005 1:05 pm

Post by chris319 »

Microsoft QuickBasic had CLEAR:
The keyword CLEAR was used in QB to erase all variables, close all files, and optionally change the stack size.
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

Post by Rescator »

If the variables are global, or you are using a global structure or list,
the easiest would be to make a procedure that re-initialize them back to their defaults.

However a VariableReset that reset specified variables to their compiletime values would be nice,
and I guess that is what you are after oryaaaaa?
merihevonen
Enthusiast
Enthusiast
Posts: 326
Joined: Mon Jan 01, 2007 7:20 pm

Post by merihevonen »

So pseudo-cally he needs this:

Code: Select all

MyVariable=12
; MyVariable at compile time, 12
[..]
For Personal_Computer=0 to 100
 OverClock(1500Mhz)
 MyVariable+1
Next
; MyVariable is now 113
[..]
ResetVariable MyVariable
; MyVariable back to 12
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> Microsoft QuickBasic had CLEAR

And the Commodore 64 has CLR which resets all variables to nothing too.
That is, strings become "" and numeric variables become 0 again. I guess
this is what he's asking for, because it resets all variables without needing
to do many loops like this: For a=1 to 1000 : var$(a)="" : Next
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
chris319
Enthusiast
Enthusiast
Posts: 782
Joined: Mon Oct 24, 2005 1:05 pm

Post by chris319 »

PB wrote:> Microsoft QuickBasic had CLEAR

And the Commodore 64 has CLR which resets all variables to nothing too.
That is, strings become "" and numeric variables become 0 again. I guess
this is what he's asking for, because it resets all variables without needing
to do many loops like this: For a=1 to 1000 : var$(a)="" : Next
Agreed. The CLEAR/CLR statement is not without precedent.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

Personally, I don't clear all my arrays before re-using them, I just use a var
to indicate the highest number. So if I had Dim a$(999) and read 250 items
into it, and then wanted to re-read just 50 items into it, I would NOT go and
clear it all first with For a=1 to 999 : a$(a)="" : Next, but rather I would just
read the new 50 items into a$(1) to a$(50) and leave a$(51-999) as they were.
It's probably a waste of memory doing it that way, but does it matter that much?
I guess I could always just do Dim a$(999) again to clear it all first, but I'm not
sure how that affects performance.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

PB wrote:Personally, I don't clear all my arrays before re-using them, I just use a var
to indicate the highest number. So if I had Dim a$(999) and read 250 items
into it, and then wanted to re-read just 50 items into it, I would NOT go and
clear it all first with For a=1 to 999 : a$(a)="" : Next, but rather I would just
read the new 50 items into a$(1) to a$(50) and leave a$(51-999) as they were.
I'm with PB on this one, that's the same way as I do it. Just got to make sure that if you sort arrays you use the optional start and finish and that way your old data doesn't get used.
Post Reply