-
This code in a public classmodule:
Code:
Friend Static Function Useoffset&(Optional offset& = -1)
Static temp&
Useoffset = temp
If offset >= 0 Then temp = offset Else temp = 0
End Function
tell me where this could be usefull. If you guess correctly what i'm using it for (and note i can't find another better way to do than this) 10 points, find another usage for it 6 points and bonus 5 points if you find a better way to do it.
Note every single keyword has to have it's purpose.
-
-
No idea where you could use that...
Code:
Friend Static Function UseOffset&(Optional Offset& = -1)
Static Temp&
UseOffset = Temp
Temp = IIf(Offset < 0, 0, Offset)
End Function
-
Nope, it's not part of kedapack :p
Immediate if's are ugly, at least from what i've heard.
Why optional? As a hint, there's one usage which is done with two calls.
-
Code:
Code:
Friend Static Function Useoffset&(Optional offset& = -1) 'declaring a freind static which means that the variables do not interfear with the rest of the code
Static temp& 'declaring a temporary value which will expire
Useoffset = temp 'the value 'USER OFF SET' is equal to the temporary vaue
If offset >= 0 Then 'if its greater thenor equal to 0 then
temp = offset ' temp is greater thenor qual to 0
Else temp = 0 ' if its under then-1 thenit is set to 0
End Function
I'm guessing thing would be useful in solving some sort of math equation.
-
keep guessing :)
math equation? hahah ok keep guessing, if you get close i'll give point
Friend means procedure is only accessible inside project, Static Function mean its shared for all objects of that class, static declaration does not expire due to procedure scope, but isn't accessible as module scope either.
-
here's another guess:
It does absolutly nothing
and is used to crash the computer
-
eh, nope it's not contradicting itself :p
-
I think
Temp is a Number holder that could be reset by Calling
the Function without a Parameter
-
-
A wrappable, resettable counter?
-
could this be used to validate numbers?
-
I just have to give a point to parksie ;) althought it's not it's ultimate purpose offset actually is a counter, and is being reset at times. But why all these specifics?
Note the calls are done in pairs.
-
are you validating a serial number
-
Nope, this code has one purpose, and parksie revealed some of it :)
-
making your own 'timer'?
counting items in arrays?
-
-
Do you call it like this?
Code:
whatever = Useoffset(Useoffset + SomeValue)
Or
Code:
whatever = Useoffset(SomeOtherFunction(blah))
where SomeOtherFunction can call Useoffset?
Perhaps it's used to count the level of recursion in functions that call each other.
-
dimava and harry: nope, another guess?
-
is it always called in pairs? It could be used to retrieve a new offset and store the old offset, then later used to get the old offset back again, but it would need to be initialised first.
Perhaps the offset that gets passed in the second time it's called is incremented from the value returned by the first call.
-
okok, Harry get's a point, but it's actually the other way round, you pass the value to retrieve it later, but since if you look it in another way, you could interpret it as returned and passed, and it actually is incremeanted between the calls. And also, yes this is used within a recursive procedure.
-
Honeybee get's 2 points for a very detailed analysis :) And yes, the parameter is passed the first time and not the second time, which is the purpose of optional in this case. There are several instancec of the class too.
Honeybee get's a third point for noticing i could replace
If offset >= 0 Then temp = offset Else temp = 0
by
If offset > 0 Then temp = offset Else temp = 0
cleaver :) but there's no actual performance gain since both comparations takes one cpu cycle.
As i've already said, it is called in pairs, and it's only used for this purpose, and it's called in combination with recursion (itself selfevidently is not recursive)
As a final hint, there's a keyword involved that should lead you to the 10 points.
Honeybee 3 points
Harry 1 point
Parksie 1 point
Active 1 point
-
Gamerelated? honeybee you knew i was working on a game, and this actually has, but the snippet is part of a scripting editor and gamedata file compiler, so it's not about moving objects around the screen but allocating space for data
-
My code is shorter ... Do I get a point now? ;)
Code:
Friend Static Function UseOffset&(Optional Offset& = -1)
Static Temp&
UseOffset = Temp
Temp = IIf(Offset < 0, 0, Offset)
End Function
'Code improved by vBulletin Tool (Save as...)
*hehe* okok, IIF is much slower BUT: my code is shorter *g
-
Okay Fox, you get a point for testing and prooving Immediate if's are slower than you thought ;) (that means slower than if statements). Actually it looks way shorter and cool, so you get the point for that, and it has cool vb-colors too, but no extra bonus points for that :)
-
Damn no points for the colors :( :( :(
*g*
-
Another very detailed report :) Okay i'll give you another point for that, but this time you you weren't as lucky as last time. The first time it's called, it doesn't handle the return value at all:
Useoffset offset
Negative value validation is of no importance either, It's only for avoiding the default value -1 since it's the first negative value i choosed it by default as default value. only 0 and positive values are passed to the function. Api calls are not involved either, except copymemory in the recursion. Okay for you and other's, there are still points to collect, even if you don't hit the 10 points, you can still beat Honeybee, with his 4 points :)
-
Kedaman - you're keeping count of the number of objects created in a control array or the number of instances of an object and use the offset to determine if there are any left. Complete shot in the dark.
-
Good guess, although no luck. I was considering give you the 6 points for another usage, but since you could simplify that by passing the offset to a counter instead it's no points, close though ;)
-
What about if I simplify things by saying that you don't need to declare the Temp var. as static because the whole function is static so it's value would be kept anyway. Just dim Temp& would do it. Must be worth a few points.
-
Clues so far :
1. It's part of a class
2. It's not part of the public interface
3. It's holds a reference of some type
A reference to the object instance in which the code is running ? The friend bit allows other objects which include your class to reference the ID so it would become a kind of object handle ?
-
3 points.
Yes, i knew, actually i discovered about Static modifier for the function was not a actual modifier, but declared all varialbes static automatically, but instead of mentioning it i waited for someone to notice it :) 1 point for that. The problem was solved easily, the recursion needs the reference object to be passed, so that you can call it from there. 2 points for hitting me right there. No the offset is not the handle, it's as said passed with the recursion, Friend is not used in that sense either. That was pretty close Paul, much is now revealed so anyone could easily get the 10 points now ;)
-
You're using it to create a call stack which you can collapse gracefully ? Useoffset is used to store the child process ID which is kicked off. Then if the object which created the child is terminated it can remove the child before closing neatly thus avoiding memory leaks ?
-
Whoa, you have ideas. i'm not doing anything in that direction, but if you elaborate it a bit convicing me you could use it for this purpose, i'll give you the 6 points. All keywords have it's purpose, except the superfluous Static modifier
-
Ok but it'll have to wait until tomorrow now. See you then.
-
hmm not really honeybee, could you explain how you think it all fits together?
-
To clean things up:
its used in a class module
if you call the function with no parameter you get 0
its stored to be used later
its a couter that can be reseted
does this have to do with the High Score part of the game?
guess 1:
somehow validating if the player did what they were supposed to, and if so, then they get a point, which would be stored, so when they get another point, the points would be added
guess 2:
stores the file name?
guess 3:
random number generator
I am positive it has to do with numbers :D
-
It's something to do with finding data in a file where the starting position to read from in the file is dependant on the length of the previous item of data in the file. So each time you read in a data structure you set the new offset for the next read.
Or
The offset is the length to read in when you don't know the length of the data coming in, and you get the length from a header of some description.
Closer?
-
kedaman, it's obviously not a counter, you must be using it to store a value which a friend looks at and uses. Therefore it must provide that friend with a piece of information which relates to the object itself. It returns 0 if it has never been set but some number if it has.
Therefore the object (A) must put a value into offset so that object (B) can read it. The name offset might mean that it is some kind of memory pointer to something which A has created and B wants to access.
Is that worth any points ?
Going back to what I said yesterday you could use this routine to create a linked list of objects with Temp holding the name of the parent object. When the parent object is removed from the list then all children who have the parents name in Temp also get unloaded. You could create a tree structure with each node holding an object. Might be useful for mapping documents ( which contain many sub-documents ) or directory structures with each node a document or directory full of details and capable of running methods against those docs/dirs.
Just a thought.
-
ok dimava, you get a point for most amount of guesses , but no more points for similar approach, yep it has to do with numbers, if you guess a couple of more times you maybe hit something..