logo
down
shadow

Changing global variable by user input via function


Changing global variable by user input via function

By : bellco
Date : November 22 2020, 04:01 AM
I wish did fix the issue. First off, I commented out the parts not relevant to the question as I did not have that code.
NOT having a global is a good practice. In order to do that, I created a module that included your function as well as a way to get and set the private value through the module. There are likely simpler ways (not having to do new MyApp) but I used that to show how you can create an instance of the app with unique values. For example you might include var myOtherApp = new MyApp("2017-08-23"); for a second instance.
code :
/*
import Map from 'ol/Map.js';
import View from 'ol/View.js';
import TileLayer from 'ol/layer/Tile.js';
import OSM from 'ol/source/OSM.js';
import TileWMS from 'ol/source/TileWMS.js';
*/
var MyApp = function(setDate) {
  /*  Private variables and functions that only
      other private or public functions may access
      and cannot be accessed outside this Module
  */
  // set a date as sent or use the default
  var iAmPrivate = setDate || "2018-10-19 08:00:00";

  /* Properties and methods contained by 
     this object being returned will be public
     and  be accessible in the global scope.
  */
  return {
    set inputvp(value) {
      iAmPrivate = value;
    },
    get inputvp() {
      return iAmPrivate;
    },
    /* probably want parsing of the date etc. in here */
    doStuff: function() {
      var nameElement = document.getElementById("someInput");
      inputvp = nameElement.value;
      console.log(inputvp);
    }
  }
};

// Create a app with data for date text
var myApp = new MyApp("2018-12-13 11:30:00");
console.log(myApp.inputvp);
myApp.inputvp = "2018-7-13 14:22:00"
console.log(myApp.inputvp);
let gotodate = document.getElementById('go-to-date');
let inputDate = document.getElementById('someInput');
// put value in the input (could be done in an app function also)
inputDate.value = myApp.inputvp;
gotodate.onclick = myApp.doStuff;

/*
    var wmsSource = new TileWMS({
      url: 'http://localhost:8080/geoserver/Observations/wms',
      params: {
        'LAYERS': 'Observations:Obs',
        'TILED': true,
        viewparams: 'chosen_timestamp:' + myApp.inputvp
      },
      serverType: 'geoserver',
      crossOrigin: 'anonymous'
    });

    var wmsLayer = new TileLayer({
      source: wmsSource
    });


    var view = new View({
      center: [0, 0],
      zoom: 1
    });

    var map = new Map({
      layers: [wmsLayer],
      target: 'map',
      view: view
    });
    */
#map {
  border: solid lime 1px;
}
<head>
  <title>Tiled WMS</title>
  <style>
    #map {
      width: 50px;
      height: 50px;
    }
  </style>
</head>

<body>

  <div id="map"></div>
  <input id="someInput" type="text" />
  <button type="button" id="go-to-date">GoToDate</button>
  <script src="./index.js"></script>
</body>


Share : facebook icon twitter icon
Changing User-Defined Global Variable Value in ExpressionEngine

Changing User-Defined Global Variable Value in ExpressionEngine


By : gowtham
Date : March 29 2020, 07:55 AM
To fix this issue You can use the PHP $GLOBAL Superglobal Array, for such cases. Say you have written a variable in any block of a particular page as $a = 123;.
Now in the same page, but in another block, you can easily change it to something else as $GLOBALS['a'] = 456;.
Function not changing global variable

Function not changing global variable


By : David Beatrice
Date : March 29 2020, 07:55 AM
I hope this helps . Your issue is that functions create their own namespace, which means that done within the function is a different one than done in the second example. Use global done to use the first done instead of creating a new one.
code :
def function():
    global done
    for loop:
        code
        if not comply:
            done = True
Python: changing global variable and global list elements inside a function

Python: changing global variable and global list elements inside a function


By : elmuria
Date : March 29 2020, 07:55 AM
it fixes the issue Use global variable:
code :
verifier = 0

def newlist():
    if verifier == 0:
        return ["A","B","C","D","E","F","G","H","I"]
    elif verifier == 1:
        return ["0","1","2","3","4","5","6","7","8"]

print newlist()

def main():
    global verifier
    verifier = 1
main()

print newlist()
verifier = 0
letters = ["A","B","C","D","E","F","G","H","I"]
if verifier == 0:
    letters = ["A","B","C","D","E","F","G","H","I"]
elif verifier == 1:
    letters = newlist()
def newlist(verifier):
    if verifier == 0:
        return ["A","B","C","D","E","F","G","H","I"]
    elif verifier == 1:
        return ["0","1","2","3","4","5","6","7","8"]

def main():
    print newlist(0)
    print newlist(1)
main()
letters = {
    0: ["A","B","C","D","E","F","G","H","I"],
    1: ["0","1","2","3","4","5","6","7","8"]
}

print letters.get(0, None)
Why is function not changing global variable even after specifying global

Why is function not changing global variable even after specifying global


By : user5698917
Date : March 29 2020, 07:55 AM
around this issue startup does not store an expression, it stores the result of an expression, once.
In other words, the variable startup references the result of 50 + addon, which at the time is the integer 70.
code :
startup = lambda: 50 + addon
def click():
    global addon
    addon *= 2
    print addon, startup()
Changing a global variable in a function without using global keyword

Changing a global variable in a function without using global keyword


By : Jayshree
Date : March 29 2020, 07:55 AM
I hope this helps you . You need the global keyword when you want to rebind the global variable to a different object. But you don't need it if all you want to do is change a mutable object. In your case L is a list and can be mutated in place with a slice operation L[:] = k. To demonstrate:
code :
>>> L = [1,2,3]
>>> 
>>> def L_value_Change(k):
...     L[:] = k
... 
>>> old_id = id(L)
>>> L
[1, 2, 3]
>>> L_value_Change([4,5,6])
>>> assert id(L) == old_id
>>> L
[4, 5, 6]
>>> 
Related Posts Related Posts :
  • Model aggregating in viewer - coordinate issue
  • Send post data like curl
  • sorting array with decimal value in specific order using javascript
  • Javascript - object.offsetTop and .offsetLeft gives 0
  • Remove content of p tag
  • Line 28: Expected an assignment or function call and instead saw an expression
  • How to trigger hover programmatically in chartjs
  • How to create a function to avoid repetitive steps?
  • Parameter the property used to filter an array
  • Return array with fast-csv in Node
  • If statement with parenthesis in javascript
  • Connecting the Javascript CSS to the CSS
  • Empty table cells
  • How to trouble shoot "NaN" error when the call to a function and assigning to let is the only visible issue
  • React / Javascript - how to filter data received to a filtered list of columns?
  • Javascript Await reserved keyword error inside if statement
  • How could I create an array on the fly?
  • How to make holes in polygons to display each one with clean colors on Google map?
  • Passing props to Children of Children (nested component tree)
  • onSelect option with get request
  • how can i test a computed property in vuejs using jest?
  • function not called after a change event
  • How to set a PHP session value as selected onclick on a drop down list
  • scrollIntoView does not include border
  • Javascript number comparison not correct
  • how to fix google map center location in vue js
  • Replace integer in a for loop with string
  • Replace nested JavaScript Object data item with dynamically created path?
  • Cannot remove item from shopping cart in React Redux reducer
  • How to import all images from a folder in ReactJS?
  • How to enforce Webpack 4 to detect and recompile only files that were changed
  • How to use arrow functions with main class 'this' properties?
  • Dynamically decide which Fetch response method to use
  • SVGRenderer with OrbitControls shows two SVG elements on opposite sides
  • JS nesting problem, variable comes back unidentified any way
  • An Alternative to <script> tag if resource don't get loaded
  • Javascript for loop behaviour in arrays
  • How to display two web content on same browser alternatively on click without reloading it?
  • How to call function inside the inner.html
  • React progress bar with each click
  • Copy text to clipboard from hidden input is not working in jQuery
  • How to populate all the array values to a single index in javascript
  • Checkbox input staying checked?
  • Change string on each loop iteration
  • React Native Fetch Requests are not getting sent to my Node Js backend for some users
  • jQuery Validation Add Method Regex Number with Parentheses
  • Do something if element equals value and is checked
  • display json data in bootstrap card using jquery
  • What prevents abuse of Firebase's createUserWithEmailAndPassword?
  • Karma + Jasmine (Angular Testing): Where should I define mock classes and test variables?
  • Call() method fails to generate output in javascript
  • Obj iteration dynamically - javascript
  • How to convert nested array to normal array and change types?
  • Javascript copy to clipboard only works if I have a breakpoint
  • different CSS style class on page load for mobile and desktop
  • JavaScript - Daterangepicker, isInvalidDate method enabling only one day
  • Javascript, Jquery: get element by two attr?
  • JavaScript colour changer doesn't work properly
  • Stop next execution of Rxjs observer?
  • Remove rules required from an input date
  • shadow
    Privacy Policy - Terms - Contact Us © bighow.org