Limiting a variable (For money system)

This forum is meant for requesting technical support or reporting bugs.

Moderators: time-killer-games, Vengeance66, Candle, reneuend, GM-Support

Limiting a variable (For money system)

Postby ZeornWarlock » Sun Sep 07, 2008 4:56 pm

Hi all,

How can I add a limit to this code? (Say I want the limit to be 12 so a player can not own more than that.)

Code: Select all
Money = Money + 1



ZW.
You have to make some to understand some.
User avatar
ZeornWarlock
Expert Member
 
Posts: 347
Joined: Tue Jun 05, 2007 12:52 am
Location: In front of the monitor.

Postby Lyberodoggy » Sun Sep 07, 2008 6:00 pm

Just check using an if every time:

If money>=12 then money=12
User avatar
Lyberodoggy
Administrator
 
Posts: 2526
Joined: Sat Feb 17, 2007 3:31 pm
Location: Athens

Postby Chromegloss55 » Sun Sep 07, 2008 6:30 pm

I know Lyberodoggy answered your question, but here's just a little something extra:

Or if you want a variable limit then use this code:

(1) Create a variable called 'Limit'
Set the value of the variable to the maximum amount of money the player is allowed

(2) Use this code everytime:

Code: Select all
If Money => Limit then Money = Limit


This means that throughout the game, you'll be able to actively adjust how much money the player can have. (For example: they might get an upgrade that allows them to carry more money).

Hope that helps a bit,
Chromegloss...
_________________
Knight Rider Forum
Last edited by Chromegloss55 on Tue Feb 24, 2009 3:26 pm, edited 1 time in total.
Chromegloss55
Forum Master
 
Posts: 630
Joined: Sat Nov 03, 2007 2:49 pm
Location: God Knows!

Postby ZeornWarlock » Sun Sep 07, 2008 7:25 pm

Thanks to both of you. :)

Chromegloss55,

How would money recognize limit? I suppose money has to be replaced by limit in that case, right?

To be honest, I want to use this to create an attribute system for my game(s). (The money variable seemed a good start for this.) ;)

Now the hard part will be the following. I have attributes. (Probably 6 of them) However, I want the player to have a minimum of 3 points in each, and then let the player spend and distribute an amount of 10 wherever he/she wants. (Limit would be 12 just the way you guys helped me.)

Any suggestions or solution to create this without tons of variables? The reason I ask, is that I will also need to keep track of enemies and allies attributes too. :? I am sure I am getting way over my head with lol!

Just trying to know if this is possible and I am sure I am not the only one wishing to see such a system.

ZW.
You have to make some to understand some.
User avatar
ZeornWarlock
Expert Member
 
Posts: 347
Joined: Tue Jun 05, 2007 12:52 am
Location: In front of the monitor.

Postby Lyberodoggy » Sun Sep 07, 2008 10:02 pm

The bad news is that Arrays don't save themselves in AM, because then you could have:

Enemysnamearray(0)=1
Enemysnamearray(1)=5

etc, where the subscript (number between parentheses) symbolizes an attribute (0 for atrribute1, 1 for attribute2 etc)

The good news is that you can store the configuration of your player's and enemies' attributes in .ini files and make the game read them from there.

Example:
In character creation, after storing each attribute into local variables, use this code:

Code: Select all
Action.WriteIni "char.ini",1,1,firstattributevalue
Action.WriteIni "char.ini",1,2,secondattributevalue

etc until you store each attribute's value.

To store enemy attributes use an index for each enemy other than 1 that is used for the player.
So, go to the option "Execute Some Script When The Game Starts or a Saved Game Is Loaded" and write some script to update your ini:
Code: Select all
Action.WriteIni "char.ini",2,1,firstattributevalueenemy1
Action.WriteIni "char.ini",3,1,firstattributevalueenemy2

etc.


To read an attribute use the ReadINI command:

Code: Select all
return_value = Action.ReadINI(FILENAME, SECTION, KEY)


See the Language Reference section for more help.
User avatar
Lyberodoggy
Administrator
 
Posts: 2526
Joined: Sat Feb 17, 2007 3:31 pm
Location: Athens

Postby ZeornWarlock » Mon Sep 08, 2008 12:39 am

Thanks, Lybero! I will try it. :)

ZW.
You have to make some to understand some.
User avatar
ZeornWarlock
Expert Member
 
Posts: 347
Joined: Tue Jun 05, 2007 12:52 am
Location: In front of the monitor.

Postby Chromegloss55 » Mon Sep 08, 2008 11:22 pm

Ah... the old INI files.

I don't think they're explained well in the AM Help Guide. I'll have to include them in my next update of 100 VB Techniques.

By the way, I'll be updating with 30 brand new techniques bringing us up to 50.
_________________
economic predictions 2009
Last edited by Chromegloss55 on Tue Feb 24, 2009 3:26 pm, edited 1 time in total.
Chromegloss55
Forum Master
 
Posts: 630
Joined: Sat Nov 03, 2007 2:49 pm
Location: God Knows!

Postby ZeornWarlock » Tue Sep 09, 2008 7:52 am

Chromegloss55 wrote:Ah... the old INI files.

I don't think they're explained well in the AM Help Guide. I'll have to include them in my next update of 100 VB Techniques.

By the way, I'll be updating with 30 brand new techniques bringing us up to 50.


When is your update? :P

ZW.
You have to make some to understand some.
User avatar
ZeornWarlock
Expert Member
 
Posts: 347
Joined: Tue Jun 05, 2007 12:52 am
Location: In front of the monitor.

Postby Chromegloss55 » Wed Sep 10, 2008 9:40 pm

ZeornWarlock wrote:
Chromegloss55 wrote:Ah... the old INI files.

I don't think they're explained well in the AM Help Guide. I'll have to include them in my next update of 100 VB Techniques.

By the way, I'll be updating with 30 brand new techniques bringing us up to 50.


When is your update? :P

ZW.


Hopefully by the end of the month.

I should've actually updated ages ago, but I got distracted.

Also, I have this habit of going back to old techniques and then completely re-doing them. It makes progress very slow.

Also, the techniques have to have some sort of order to them. I want to leave the really complicated stuff to the last 20 techniques.

But anyway, the answer to your question: I'll hopefully have them done by the end of the month.
_________________
Lenders mortgage insurance Forum
Chromegloss55
Forum Master
 
Posts: 630
Joined: Sat Nov 03, 2007 2:49 pm
Location: God Knows!


Return to Adventure Maker Technical Support and Bug Reports

Who is online

Users browsing this forum: No registered users and 0 guests