Assigning Type Value to Global Variable

Blitz3D Forums/Blitz3D Programming/Assigning Type Value to Global Variable

Roland(Posted 2006) [#1]
Hey all,

This is probably a really stupid question, but I can't seem to work it out. I have a type for a slider (gui object) which I want to control a global variable (actually I want to create a whole bunch of them for an editor I'm working on)... Anyway, I can't seem to figure out how to get that type's value to propagate into the global variable.

In other words, if I have a global variable named "testvar", and I want to continuously update testvar to equal the value of slider\currentvalue#, how would I do that?

Right now, I'm passing the global variable name to the type as a field called "variable$". But when I go to set that equal to the value of the slider (slider\variable = slider\currentvalue#), it doesn't update the global variable, instead it resets the type field to equal just the current value of the slider.

That's probably as clear as mud, but hopefully someone will be able to sort it out and give me a hand!

Thanks,
Roland


stayne(Posted 2006) [#2]
Global testvar#

;main loop
testvar# = slider\currentvalue#

?


Roland(Posted 2006) [#3]
Hey, thanks for the quick reply!... I know that will work, but I need to have each instance of a slider that i make have it's own global variable that it updates... So it needs to be able to update generically. See what I mean? I can't use the name of the global variable directly, because I'll need to loop through all of my types. So the variable to be updated needs to be assigned to a field inside of the type...

Wow, that sounds really confusing. Let me know if it's clear enough to figure out :)

thanks,
roland


stayne(Posted 2006) [#4]
i understand what you want but i don't understand the logic behind it. maybe it's just something out of my league :)

good luck!


WolRon(Posted 2006) [#5]
Dim testvar#(100)

;main loop
testvar#(slider\globalvarID) = slider\currentvalue#


Roland(Posted 2006) [#6]
Yup, looks like that one will work... A little extra fancy footwork to continuously update the variables, but nothing too complex. Thanks!


octothorpe(Posted 2006) [#7]
If you're going to do that, you might as well avoid the updating footwork and do this:

Dim relevant_slider.slider(100)

Print relevant_slider(id)\value ; get global variable


I could probably offer more useful suggestions if I knew what these global variables were for. Replacing the array with a hash table might make a lot of sense here.