|
Hi. So I want to make clickalbe buttons that changes variables. I have following code:
...and when i click button "-" or "+" nothing happens. I noticed, then if i will extend code from a function and type variables by hand - everything works! There is a webdemo, if somebody want to see it in action: click here.
(comments are locked)
|
|
There is a hackish way of doing this in Javascript if you really want. Since classes are always passed by reference and not by value, you can make a class for your variables (that would normally be passed by value) that you want to be directly affected by functions. The class can work basically the same way as a normal passed-by-value variable, but takes more work to set up and use. Here's an example that makes a class called RefFloat, that is basically a float, except you can use it like a reference variable. The DoubleButton function will make a button that doubles the value of any RefFloats that are passed in. Woaw! You're the best! Thank you!
Apr 13 '10 at 12:56 AM
Rafal Sankowski
(comments are locked)
|
|
Variables like ints and floats (which are passed by value) in functions are local to that function, so when you increase/decrease To get around that, you can affect the actual variables you're passing in by using reference variables instead of standard local variables. However, while you can use functions that have reference variables in Javascript, you can't make them. For that you need to use C# instead. It's very possible to make that function as a separate C# script, and keep the rest of the script in Javascript, if you're more comfortable with that. Thank you for that quickly feedback! If I can't do it by functions (because I don't wanna use C#) - is there any other way? I don't want to copy that much of code.
Apr 12 '10 at 11:11 PM
Rafal Sankowski
@Rafal Sankowski: Well, actually there is another way (see my other answer), but frankly it's easier to use C# for this sort of thing. Remember you'd only have to use it for that one function and nothing else.
Apr 12 '10 at 11:30 PM
Eric5h5
(comments are locked)
|
