Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

declaring (an setting var's values) from Switch event

Avatar

Level 4

H folks,

I'm a syntax issue (I hope that's all) with how you declare and set var's values with switch statements

below is a commented version of what i'm attempting (which should clarify the issue)

Var fav_colour; // i dont know where/how to declare these var's in a switch

Var fav_food;

//and so on letting me declare and manipulate values based on switch selection…

switch (this.rawValue) {

case "1":

fav_colour.rawvalue = “blue”;

fav_food.rawvalue = “Apples”;

///and so on to post variable values (which can then be used in (java version of a) concatenated environment e.g. X.rawvalue = a1.value + fav_colour.rawvalue + fav_food.rawvalue + a2.value or similar…… mostly values wont be displayed in their own form fields just concatenated...

break;

case "2":

fav_colour.rawvalue = “red”;

// am I right in thinking that just because you declare two var’s you don’t require values for both of them in each switch instance {acknowledging this could lead to “null” being inserted …..}

break;

case "3":

fav_colour.rawvalue = “grey”;

fav_food.rawvalue = “oranges”;

// and so on…

// these var’s and values will be used almost exclusively in as noted under case “2”: ie java spliced together to form output strings

}

Thanks folks

1 Reply

Avatar

Level 10

Hi Greg,

It may just be the way you have posted, but there are two things:

"Var" should be "var"

and

".rawvalue" should be ".rawValue"

If the variables are global variables then you need to use the .value to access and set the value of the variable. However if they are script variables, then you don't need the .value (or .rawValue)

var fav_colour; // declared but not set

var fav_food;

...

some script

...

fav_colour = "Red";

fav_food = "Apples";

You can also set the value of the variable, when you declare it:

var fav_colour = "Red"; 

Hope that helps,

Niall