inherit
182418
0
May 22, 2014 16:13:12 GMT -8
SuperJedi224
29
August 2012
superjedi224
|
Post by SuperJedi224 on Sept 7, 2012 14:12:44 GMT -8
Just wondering- is there any way to write a script that edits itself or another script when an event is triggered? Maybe something like this:
01: variable=1 02: If variable=1 03: Create (Image) 03: When (Image) is clicked: 04: Replace Line 01 position 10 with "0" 05: End 06: End 07: End
Would something like this be possible in Javascipt (with the change in line 4 actually affecting the source code)? I can't find any tutorials for this.
|
|
inherit
126477
0
Apr 21, 2023 15:18:52 GMT -8
Shrike
Re-appeared briefly after 6 years only to no doubt disappear again.
1,569
June 2008
shrike
|
Post by Shrike on Sept 7, 2012 14:37:19 GMT -8
It's less a case of "self-editing" in your example but simply changing the variable. So your line 4 psuedocode could simply be "set variable to 0" Are you going by experience from another language where you can't change/don't have variables? (that said, I can't think of any that don't )
|
|
inherit
182418
0
May 22, 2014 16:13:12 GMT -8
SuperJedi224
29
August 2012
superjedi224
|
Post by SuperJedi224 on Sept 7, 2012 15:08:29 GMT -8
It's less a case of "self-editing" in your example but simply changing the variable. So your line 4 psuedocode could simply be "set variable to 0" Are you going by experience from another language where you can't change/don't have variables? (that said, I can't think of any that don't ) I mean having the code rewrite itself so in later instances the initial value is different.
|
|
inherit
126477
0
Apr 21, 2023 15:18:52 GMT -8
Shrike
Re-appeared briefly after 6 years only to no doubt disappear again.
1,569
June 2008
shrike
|
Post by Shrike on Sept 8, 2012 2:23:48 GMT -8
What would be prompting a change in the initial value? It might be easier if you explain what it is you're wanting to do, because the example you've given above wouldn't even do anything. You might find some of these resources helpful as well, specifically this one about variables.
|
|
inherit
130228
0
Jul 11, 2024 19:19:59 GMT -8
Charles Stover
1,731
August 2008
gamechief
|
Post by Charles Stover on Sept 13, 2012 9:15:37 GMT -8
I'm not sure you fully grasp the concept of a variable if you ask this.
But, no, there is no way for this to happen. That's just not how JS works. There is no reason for that to need to happen, either.
|
|
#00AF33
Bark Different.
102833
0
1
Feb 12, 2023 16:57:46 GMT -8
RedBassett
I'm a Marxist/Lennonist of the Groucho/John variety.
15,405
April 2007
applecomputer
RedBassett's Mini-Profile
|
Post by RedBassett on Sept 13, 2012 13:31:28 GMT -8
Also to add to the voices above, note that this wouldn't be a way to store values over time, as a page reload would reset the variable to the original default. If you want to set a default and store it, you would need to use forms or AJAX to store the variable on the server side.
|
|
inherit
130228
0
Jul 11, 2024 19:19:59 GMT -8
Charles Stover
1,731
August 2008
gamechief
|
Post by Charles Stover on Sept 15, 2012 13:41:32 GMT -8
Or JavaScript cookies.
|
|
#00AF33
Bark Different.
102833
0
1
Feb 12, 2023 16:57:46 GMT -8
RedBassett
I'm a Marxist/Lennonist of the Groucho/John variety.
15,405
April 2007
applecomputer
RedBassett's Mini-Profile
|
Post by RedBassett on Sept 15, 2012 15:00:34 GMT -8
You smart person. Yes. Cookies work too.
|
|