Question concerning Variables

  • #1, by crazyduckgamesThursday, 07. May 2020, 14:53 4 years ago
    I´m trying my hand at variables for the first time right now, setting and showing variables is no problem. But i´d like to do something else. I hope i can explain:

    Var01 = (Var02x2)  <- Like this. If Var02 changes in the game, Var01 is supposed to change, too. But i don´t see any way to do this with the standard actions available. Is that even possible somehow? It seems like a simple calculation, but i just can´t find anything.

    Newbie

    8 Posts


  • #2, by MachtnixThursday, 07. May 2020, 18:52 4 years ago
    Wenn du Variablen im Editor definieren und anzeigen lassen kannst, sollte es auch mit einer Kalkulation gehen. Vorher musst du natürlich Var01 und Var02 definieren und mit einem Startwert belegen. Ich habe es noch nicht probiert, sondern immer ein winziges Lua-Script dafür verwendet.

     If you can define and display variables in the editor, you should also do a calculation. Of course, you must first define Var01 and Var02 and assign a starting value. I haven't tried it yet, I've always used a tiny Lua script for it.

    Thread Captain

    1097 Posts

  • #3, by afrlmeThursday, 07. May 2020, 20:34 4 years ago
    I've no idea if this code is correct. You will need to edit "example" & "example2" & replace them with the names of the value you want to listen out for when you change it, & with the name of the value you want to set the same as the value you just changed - names are case sensitive. Anyway, add this script to the script section of the editor. make sure the script is set as definition type.

    local SET_VALUE = 70
    
    system.registerActionPartHook(Set_VALUE, "setValue")
    
    
    
    function setValue(actionPart)
    
    
    
      if actionPart.Link == Values["example"] then
    
        Values["example2"].Int = actionPart.Link.Int
    
      end
    
     
    
      return false -- (false = update action part, true = kill action part)
    
    
    
    end

    Imperator

    7278 Posts

  • #4, by MachtnixThursday, 07. May 2020, 20:39 4 years ago
    I'm not sure, but I think, Crazyduckgames wanted to do this in the editor. You can set values everywhere and make requests, but I don't know, you  can use terms and calculations instead of integer values?
    But i don´t see any way to do this with the standard actions available. Is that even possible somehow?

    Thread Captain

    1097 Posts

  • #5, by afrlmeThursday, 07. May 2020, 21:33 4 years ago
    You can set a value by linking it to another value with action parts, but if you were going to do that, then you might as well just manually do it anyway as it's the same amount of action parts, no?

    Anyway, in the set value action part there's 2 value parameters. the first one is the value you want to change. if you specify a second value then it will set the value the same as the linked value, but like I said, it's kind of pointless because you would still need to do 2 set value action parts to change both values.

    The script I wrote/shared is an event listener that listens out for when the set value action part is executed, then does whatever you have told it to do, which in this case would be changing the value of value B to value A if set value action part was used on value A.

    The editor doesn't contain any functions like that as it's purely for visually creating your games - maybe it would be possible with the visual scripting section? I haven't looked into that side of the editor yet.

    Imperator

    7278 Posts

  • #6, by crazyduckgamesThursday, 07. May 2020, 21:38 4 years ago
    Thanks to the both of you, but i have a feeling i can´t really do what i want to. Concerning the script example, i don´t see that code doing as i want, either. To clarify my example a bit:

    I have a value called "MaximumSettler" and a value "NumberofTents". If i have 1 tent, i can have 2 Settlers. (MaximumSettler=(NumberofTents*2)) If i get another tent, i can have 4 settlers and so on. But i guess i can´t do that in any easy way. Which is a bit sad, since it pretty much kills my whole game idea.

    Newbie

    8 Posts

  • #7, by afrlmeThursday, 07. May 2020, 21:55 4 years ago
    Ok, your initial post didn't really make much sense. You can use the script I provided for that, no problem. Here you go. wink

    local SET_VALUE = 70
    system.registerActionPartHook(SET_VALUE, "setValue")
    
    function setValue(actionPart)
    
      if actionPart.Link == Values["NumberofTents"] then
        Values["MaximumSettler"].Int = (actionPart.Link.Int * 2)
      end
     
      return false -- (false = update action part, true = kill action part)
    
    end

    Imperator

    7278 Posts

  • #8, by afrlmeFriday, 08. May 2020, 12:14 4 years ago
    I made a quick example - I'm using the latest version of Visionaire by the way.

    Anyway, you can decrease or increase the amount of tents with the left & right arrow keys on your keyboard. I had to add a setDelay function inside of my script as it needs to wait for the tents value to update before updating the max_people value. But as you can see it's working ok. smile


    * edit #1: also I'm a big dumb-dumb. You could technically do this entirely with action parts too. d'oh!

    1. create a called by other action block somewhere. rename it to update_max_settlers.

    2. add these action parts to it...

    set value "MaximumSettler" as value "NumberofTents"
    set value "MaximumSettler" * 2

    3. now whenever you update the "NumberofTents" value create a call action action part & call the called by other action part you just created.

    & voila, no need for code as it should update the MaxiumumSettler value to the double the value of the NumberofTents value.

    * edit #2: I've updated the zip file I linked. I've included 2 ved files. The one that says _ns at the end is action parts only & the one that says _ws at the end is using the event listener script. Either way, enjoy. wink

    Imperator

    7278 Posts

  • #9, by crazyduckgamesSaturday, 09. May 2020, 21:26 4 years ago
    Thank you, it´s working! Now i just need to find a way to "refresh" the screen to show the changes in value right after they happened. But that shouldn´t be too difficult, changing scenes for a second should do the trick.

    Newbie

    8 Posts

  • #10, by afrlmeSaturday, 09. May 2020, 21:30 4 years ago
    Are you displaying the values with display object text action parts? If you are you can just do those same action parts again to update the text - you can see how I did that in the examples I shared with you.

    * edit: Lua draw would be a good solution for drawing stats/gui stuff on the screen because the draw functions are loops that get updated constantly, so if you link things that dynamically change inside of a draw function then the draw function would immediately reflect that change on the next loop.

    Imperator

    7278 Posts

  • #11, by btd3dThursday, 21. May 2020, 20:55 4 years ago
    I was reviewing your example and I was wondering how the increment and decrement are bound to the left and right keys.  Can you explain how that is done?

    Newbie

    1 Posts