Progress Bar/Percent?

XanMag
I would love to have a progress bar somewhere in one of my info boxes on the right during game play. I think the easiest way to implement it is to divide the current number of points earned by the total number available, but I have NO clue how to do this. If someone could give me an easy solution, I'd love it!

Thanks!

jaynabonne
Here's a quick stab:

<!--Saved by Quest 5.6.5783.24153-->
<asl version="550">
<include ref="English.aslx" />
<include ref="Core.aslx" />
<game name="progress test">
<gameid>23d85b56-0b5f-48c3-8fb1-e28d47a63179</gameid>
<version>1.0</version>
<firstpublished>2015</firstpublished>
<statusattributes type="stringdictionary">
<item>
<key>percent</key>
<value><![CDATA[<div style="width:100%; height:24px; border:1px solid black;"><div style="background-color:blue;width:!%;height:100%"></div></div><div style="text-align:center">!%</div>]]></value>
</item>
</statusattributes>
<percent>25</percent>
</game>
<object name="room">
<inherit name="editor_room" />
<object name="player">
<inherit name="editor_object" />
<inherit name="editor_player" />
</object>
</object>
</asl>

This is a status attribute that uses some HTML/CSS magic to show a progress bar, based on the "percent" status attribute.
At 25%, it looks like this:
Capture25.PNG

and at 50%, it looks like this:
Capture50.PNG

I dropped the number in, but you might not want or need that (e.g. you could have a separate status variable beneath the bar instead of doing it all together like I did). If you want it to look different, let me know, and I'll give you modified HTML, unless you can work that part out yourself. :)

XanMag
jaynabonne wrote:If you want it to look different, let me know, and I'll give you modified HTML, unless you can work that part out yourself. :)


:lol: Thanks. It looks great, but you have overestimated my coding ability! I have NO clue how to implement it. I did copy-paste the code
    <statusattributes type="stringdictionary">
<item>
<key>percent</key>
<value><![CDATA[<div style="width:100%; height:24px; border:1px solid black;"><div style="background-color:blue;width:!%;height:100%"></div></div><div style="text-align:center">!%</div>]]></value>
</item>
</statusattributes>
and it worked. But, I need to know how to calculate the % progression. I assume I need to have the arithmetic in this part
<percent>25</percent>
somewhere but... again... NO clue!

I figured that the easiest way would be to divide the current score by the total available. That way, I wouldn't have to add anything new to my code within the game. How would I go about putting that into code? Your help is greatly appreciated! Thanks!

jaynabonne
Here it is augmented a bit.

<!--Saved by Quest 5.6.5783.24153-->
<asl version="550">
<include ref="English.aslx" />
<include ref="Core.aslx" />
<game name="progress test">
<gameid>23d85b56-0b5f-48c3-8fb1-e28d47a63179</gameid>
<version>1.0</version>
<firstpublished>2015</firstpublished>
<statusattributes type="stringdictionary">
<item>
<key>percent</key>
<value><![CDATA[<div style="width:100%; height:24px; border:1px solid black;"><div style="background-color:blue;width:!%;height:100%"></div></div><div style="text-align:center">!%</div>]]></value>
</item>
</statusattributes>
<percent type="int">0</percent>
</game>
<object name="room">
<inherit name="editor_room" />
<object name="player">
<inherit name="editor_object" />
<inherit name="editor_player" />
<score type="int">0</score>
<maxscore type="int">100</maxscore>
<changedscore type="script">
game.percent = player.score*100 / player.maxscore
msg("percent is now " + game.percent)
</changedscore>
</object>
</object>
<command>
<pattern>inc</pattern>
<script>
player.score = player.score + 5
msg("score is now " + player.score)
</script>
</command>
</asl>

The player has score and maxscore attributes. You would just change the player's score attribute. There is a "changedscore" script that fires whenever the score attribute changes, and it will update the percent for you (so you don't have to do it yourself).

The sample game has a simple test "inc" command to make the percent go up. (You can get rid of the msg's in there if you grab the code. It was just to see what was happening.)

I've attached the file as well, in case that's more useful than the inline code. :)

Let me know if I can help with anything.

XanMag
Sorry for being a dolt here.
1. Could you tell me where to paste in my code and what exactly I need copy paste in my code?
2. How/where to input my maximum point value so that the current points get divided by the maximum?

If I need to post the beginning of my game code I can but I won't be back until Thursday night. Thanks again and I apologize that I don't understand! :lol:

 <score type="int">0</score>
<maxscore type="int">100</maxscore>


Could I just swap out that 100 for my 265? If that's true, I just need to know what exactly to copy. Thanks!

jaynabonne
So add this to your player object

	  <score type="int">0</score>
<maxscore type="int">100</maxscore>
<changedscore type="script">
game.percent = player.score*100 / player.maxscore
msg("percent is now " + game.percent)
</changedscore>


and set maxscore to your maximum score, as you said.

Then just add this into your <game> object:

    <statusattributes type="stringdictionary">
<item>
<key>percent</key>
<value><![CDATA[<div style="width:100%; height:24px; border:1px solid black;"><div style="background-color:blue;width:!%;height:100%"></div></div><div style="text-align:center">!%</div>]]></value>
</item>
</statusattributes>
<percent type="int">0</percent>

I hope you're able to do this in CodeView. If you need a GUI approach to this, I'd have to think about that more. :)

XanMag
I think I can do that! I'll let you know for sure when I get back, but seems easy enough! Thanks!

XanMag
jaynabonne wrote:I hope you're able to do this in CodeView. If you need a GUI approach to this, I'd have to think about that more. :)

Guess not... :(

I copy-pasted your code into a new game. I got rid of the 'inc' command. I added some points for picking up an item. Here is where I have isolated the problem on my end...

When you add points, here is your code:

  player.score = player.score + 2


When I add points through the GUI, here is my code:

IncreaseScore (5)


Is there a way to change your code to be able to use it in my game? I will not go through and alter all of the code for all of the points gathered in my finished game. Not worth it. I'll just implement it in my next game!

Let me know so I can get this baby released!! :D

EDIT: Meh. I'm super lazy and should have tried this before posting!! So, FYI... I simply searched (Ctrl+F) in code view "IncreaseScore" and copy-pasted
player.score = player.score + X
directly below every line I found where I increased the score. Obviously I changed the 'X' to the IncreaseScore value found in parentheses and the 'player' to Xanadu (my player name). Everything is now working properly!

Thanks a ton, Jay!

HegemonKhan
I don't know how it works and nor what the name of the built-in 'score' Attribute, but otherwise, you should be able to do:

from (Jay's):

player.score = player.score + 2

to (your usage of the built-in 'score', assuming this wil work, lol):

IncreaseScore (2)

This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums