AGS Awards votes close at 13:59 BST on Wednesday 07 March 2018. You've already voted, so you've got 14 days and 21 hours left to wait before voting closes!

Author Topic: Can I use a GUI slider to display a global variable?  (Read 261 times)

Axelord1942

    • I can help with AGS tutoring
    •  
    • I can help with animation
    •  
    • I can help with backgrounds
    •  
    • I can help with characters
    •  
    • I can help with making music
    •  
    • I can help with play testing
    •  
    • I can help with PR
    •  
    • I can help with proof reading
    •  
    • I can help with publishing
    •  
    • I can help with story design
    •  
    • I can help with translating
    •  
    • I can help with voice acting
    •  
Working on a project and I'm trying to implement a stress/sanity level, and I would like this to be reflected with a slider on the either on the action gui or elsewhere that would raise and lower respectively...is this as simple as I think it might be (just using a call//check/display function?) or am I off the mark?  First post, long-time lurker so please forgive me if this isn't in the right place after all.(laugh)
You have been eaten by a Gru

Cassiebsg

  • Cavefish
  • Fleeing the Cylon tyrrany...
    • Cassiebsg worked on a game that was nominated for an AGS Award!
Re: Can I use a GUI slider to display a global variable?
« Reply #1 on: 02 Feb 2018, 18:03 »
Hope this helps: http://www.adventuregamestudio.co.uk/forums/index.php?topic=51544.msg636504538#msg636504538

There are more threads about "health bars"... Principle is the same, just the name that changes. (laugh)
There are those who believe that life here began out there...

Axelord1942

    • I can help with AGS tutoring
    •  
    • I can help with animation
    •  
    • I can help with backgrounds
    •  
    • I can help with characters
    •  
    • I can help with making music
    •  
    • I can help with play testing
    •  
    • I can help with PR
    •  
    • I can help with proof reading
    •  
    • I can help with publishing
    •  
    • I can help with story design
    •  
    • I can help with translating
    •  
    • I can help with voice acting
    •  
Re: Can I use a GUI slider to display a global variable?
« Reply #2 on: 02 Feb 2018, 18:20 »
Thank you!  I searched around the forums but I guess I wasn't using the right terms, I'll read through all of this right away!  Thanks again.
You have been eaten by a Gru

Khris

    • Lifetime Achievement Award Winner
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
    • Khris worked on a game that was nominated for an AGS Award!
Re: Can I use a GUI slider to display a global variable?
« Reply #3 on: 05 Feb 2018, 12:36 »
Let me just point out that a slider is for input, not output. :-D

Axelord1942

    • I can help with AGS tutoring
    •  
    • I can help with animation
    •  
    • I can help with backgrounds
    •  
    • I can help with characters
    •  
    • I can help with making music
    •  
    • I can help with play testing
    •  
    • I can help with PR
    •  
    • I can help with proof reading
    •  
    • I can help with publishing
    •  
    • I can help with story design
    •  
    • I can help with translating
    •  
    • I can help with voice acting
    •  
Re: Can I use a GUI slider to display a global variable?
« Reply #4 on: 07 Feb 2018, 13:38 »
Yeah, I figured that out the hard way and switched to a button.  That project, since it really matters to me, is on hold until my scripting gets better.  Working on a less important one until i get more comfortable with it.
You have been eaten by a Gru

Re: Can I use a GUI slider to display a global variable?
« Reply #5 on: 07 Feb 2018, 18:50 »
Hey, man. A couple of months ago, I was in your shoes. But the good people on this forums helped so much, that now I understand a lot of things (still a noob, but not so much anymore :-D ). Sooo I'm confortable enough to try and help you out.
What you want is simple enough, I think. You want a stress/sanity level. Okay, your character becomes crazier and crazier when he does some things, right? We can just track this with a variable. If you're gonna have more "stats" to your character/s (like, I don't know, luck, strength, or something you'd see in an RPG), you probably should use structs, arrays, and/or extender functions but, for now, if you don't need this, I'll skip them. If you DO need them, let me know and I'll explani that.
I'm gonna assume you use stress and sanity as 2 extremes of the same variable. First you create global variable, named "stress", or whatever you want. We'll leave the default value to 0. Then, whenever your character does something that makes him more or less stressful/sane/crazy you just do this:

Code: Adventure Game Studio
  1. //you can use these anywhere in your code.
  2. stress ++; //this increases stress by 1
  3. stress --; //this decreases stress by 1
  4. stress += 10 //this increases stress by 10, you can replace that number with any number you want.
  5. stress -= 10 //the same but decreasing stress

Also you'll want to set your stress limits. In my example I made them 0 and 100, but you can do whatever you want.

Code: Adventure Game Studio
  1. //in repeatedly_execute
  2. if (stress<0){ //so you can't have negative stress.
  3.     stress = 0;
  4. }
  5. if (stress>100){
  6.     stress = 100;
  7.     //or lose the game, die, or whatever you want.
  8. }

Then, to change events depending on how much stress your character has, do something like:
Code: Adventure Game Studio
  1. cBoss.say ("You're fired.");
  2. if (stress < 25){
  3. player.say("It's okay, I'll find another job soon enough.");
  4. }
  5. else if (stress < 50){
  6. player.say("Oh yeah? Up yours, old man!");
  7. }
  8. else{
  9. Display ("You grab your chair and proceed to bludgeon your boss to death.");
  10. }
  11.  


You'll want to know how much stress your character has. You can do this in several ways:

1) By displaying it in certain circumstances (by clicking a button, for instance):
Code: Adventure Game Studio
  1. Display ("Your character has %d amount of stress!", stress); //%d displays the value of an int, in this case stress.

2) By displaying it on a GUI's label. Create a GUI for displaying you stress, and there create a label called "lblStress".
Code: Adventure Game Studio
  1. //in repeatedly_execute
  2. String StressDisplay=String.Format("Stress: %d", stress);
  3. lblStress.Text=StressDisplay;

3) Like you wanted, by using a "stress bar". I think you should combine this with method 2. I've made this a long time ago, only once, so I don't know if it's the easier method, but it works. Make a sprite of a rectangle, and make it 100 px wide (that would be our max, but you can make it whatever you want). Then make a button on your stress GUI, called btnStressBar. Use your rectangle sprite as your button's sprite. In the button's properties, make "clip image" true.
Code: Adventure Game Studio
  1. //in repeatedly_execute
  2. btnStressBar.Width=stress;


If something doesn't work, you don't understand something, or need anything else, don't hesitate to ask.



« Last Edit: 07 Feb 2018, 18:56 by Egmundo Huevoz »

Axelord1942

    • I can help with AGS tutoring
    •  
    • I can help with animation
    •  
    • I can help with backgrounds
    •  
    • I can help with characters
    •  
    • I can help with making music
    •  
    • I can help with play testing
    •  
    • I can help with PR
    •  
    • I can help with proof reading
    •  
    • I can help with publishing
    •  
    • I can help with story design
    •  
    • I can help with translating
    •  
    • I can help with voice acting
    •  
Re: Can I use a GUI slider to display a global variable?
« Reply #6 on: 08 Feb 2018, 17:56 »
This is excellent.  This template is going to help me IMMENSELY in understanding how this actually works.  The examples given in the in-program help menu leave a little to be desired (roll)

Once I get the time today I'm gonna boot up my prototype and start plugging away and see what kind of lemonade I can make.

Yeah, you pretty much nailed it though.  All I really need is the stress/sanity variable (trying to keep the game mechanics as simple as possible).
Hey, man. A couple of months ago, I was in your shoes. But the good people on this forums helped so much, that now I understand a lot of things (still a noob, but not so much anymore :-D ). Sooo I'm confortable enough to try and help you out.
What you want is simple enough, I think. You want a stress/sanity level. Okay, your character becomes crazier and crazier when he does some things, right? 

Coincidentally, have you played Darkest Dungeon? :-D
You have been eaten by a Gru

Khris

    • Lifetime Achievement Award Winner
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
    • Khris worked on a game that was nominated for an AGS Award!
Re: Can I use a GUI slider to display a global variable?
« Reply #7 on: 08 Feb 2018, 18:19 »
One can combine all that into a single function btw:

Code: Adventure Game Studio
  1. // global header
  2. import void AddStress(int amount);
  3. import int stress, max_stress;
  4.  
  5. // global script
  6. int stress, max_stress = 100;
  7. export stress, max_stress;
  8.  
  9. void AddStress(int amount) {
  10.   stress += amount;
  11.   if (stress < 0) stress = 0;
  12.   if (stress > max_stress) stress = max_stress;
  13.   lblStress.Text = String.Format("Stress: %d", stress);
  14.   btnStress.Width = stress;
  15.   Wait(1); // wait for screen repaint
  16.   // if (stress == max_stress) Die();  // uncomment to use
  17. }

That way we only update the label and button when stress actually changes.

Code: Adventure Game Studio
  1.   AddStress(10);
  2.  
  3.   // or
  4.   AddStress(-5);
  5.   Display("You calm down a bit.");

Axelord1942

    • I can help with AGS tutoring
    •  
    • I can help with animation
    •  
    • I can help with backgrounds
    •  
    • I can help with characters
    •  
    • I can help with making music
    •  
    • I can help with play testing
    •  
    • I can help with PR
    •  
    • I can help with proof reading
    •  
    • I can help with publishing
    •  
    • I can help with story design
    •  
    • I can help with translating
    •  
    • I can help with voice acting
    •  
Re: Can I use a GUI slider to display a global variable?
« Reply #8 on: 08 Feb 2018, 22:51 »
I really appreciate this input!  This is extremely insightful, and helps me put this stuff in the proper context!  I'll make sure to post results!

;)
You have been eaten by a Gru