![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Newbie
Join Date: May 2006
Posts: 16
Rep Power: 0
![]() |
compile a var name from another var
i have a script that holds the functions for a desklet. the desklet is to be ran in a program called avedesk. ultimately this block of code is meant to first check for the next side to flip to, then check if that side is enabled, then switch to it if it is, if its not, goto the next side and check it.
the variables of chk0-chk4 are ether true or false, true meaning the side is enabled false meaning it isn't and to skip it. side is the current active side of the desklet the newside stuff is just telling it if the current side is not the last side add one, else goto the first side. then we got the while loop now the problem im having is that im just starting js as this desklet program requires it. so i don't know much about the syntax and have been trying to get by on frequent Google searches. the part im having trouble with is if(newside == i && ("chk" + i) == 'true'){what im trying to do is have the var i from the loop be added after chk so that if i == 2 it work read out to: if(newside == i && ("ch" + i) == 'true'){ if(newside == i && chk2 == 'true'){ this is the best way i could come up with to get the reaction i want, i just don't know how to make the two add together. function flipnext(){
var chk0 = this.parameters('radarchk1');
var chk1 = this.parameters('radarchk2');
var chk2 = this.parameters('radarchk3');
var chk3 = this.parameters('radarchk4');
var chk4 = this.parameters('radarchk5');
side = desklet.GetcurrentSide();
if(side < 4){
newside = side + 1
}else{
newside = 1
}
i = 0
while(i < 5){
if(newside == i && ("chk" + i) == 'true'){
desklet.FlipTo(i);
alert(i);
}else if(("chk" + i) == 'false'){
newside + 1
}
i++
}
}sorry if this has been solved before, i didn't know what to call it so i didn't really know what to search for. any help on this method or maybe an alternative method would be greatly appreciated. thanks. |
|
|
|
|
|
#2 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 810
Rep Power: 4
![]() |
try
eval("chk" + i) == 'true' |
|
|
|
|
|
#3 | |
|
Newbie
Join Date: May 2006
Posts: 16
Rep Power: 0
![]() |
Quote:
|
|
|
|
|
|
|
#4 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 810
Rep Power: 4
![]() |
Re: compile a var name from another var
One of the posts that went missing in this thread (I can't remember who wrote it) pointed to this blog: Eval is Evil
I read through that and have made some modifications to some of my code that was using eval extensively to test for the existence of a list of variables. It now runs in 1/5th of the time! It was actually slowing the whole program down quite a bit, as this list has grown slowly from about 20 variables to over 500. So thanks to whoever it was who posted it previously. |
|
|
|
|
|
#5 |
|
Megalomaniac
Join Date: Nov 2006
Posts: 8
Rep Power: 0
![]() |
Re: compile a var name from another var
> So thanks to whoever it was who posted it previously.
Yeah no problems, I was as much surprised as you are regarding the missing post. ;-) Just to make matters more clear, every variable you create is a property of some object or the another. In cases where you don't have explicit namespaces declared or trying to declare a function, the parent object is the 'window' object. It is easier to remember this if you keep in mind that almost everything in Javascript is a hash with key value pairs (even arrays!). |
|
|
|
|
|
#6 | |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Re: compile a var name from another var
Quote:
Therein lies the problem. Abstraction is a moving target. To define something as "evil", whether it be an eval or a goto, is to indulge in the kind of behavior that judges a food by the taste of the wrapper.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
|
#7 | ||
|
Megalomaniac
Join Date: Nov 2006
Posts: 8
Rep Power: 0
![]() |
Re: compile a var name from another var
Quote:
Quote:
|
||
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| please help me to compile | cwl157 | C++ | 37 | Mar 6th, 2006 6:12 PM |
| MASM32 compile problem | Kilo | Assembly | 3 | Nov 20th, 2005 12:39 PM |
| can't compile code | lloydkirk | Java | 17 | Oct 6th, 2005 2:07 AM |
| Fahrenheit / Celsius compile problem | andrewgray | C++ | 20 | Jul 8th, 2005 11:04 PM |
| C++ Compile | gebreil | C++ | 6 | May 29th, 2005 1:30 PM |