TinTin++ Mud Client The TinTin++ message board

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
TinTin++ Mud Client

Saving Vars to Class Files - #Math doesn't update?

 
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> Script Help
View previous topic :: View next topic  
Author Message
new_to_tin_tin



Joined: 05 Jan 2011
Posts: 38

PostPosted: Mon Jan 08, 2018 11:01 am    Post subject: Saving Vars to Class Files - #Math doesn't update? Reply with quote

This code didn't save the variables correctly until I added
Code:
#var icefall_crumbled {$icefall_crumbled};
#var icefall_crumbled_qty {$icefall_crumbled_qty};
>
To this file:
Code:
#class icefall_crumble_tracker open;
#var {icefall_crumbled} {0};
#var {icefall_crumbled_qty} {0};
#class icefall_crumble_tracker read {$dirscripts/savedata/icefallcrumblesdata.tin};
#action {^%1 crumbles into %2 gold pieces.$}{
        #if {"$GMCP[ROOM][INFO][zone]" == "icefall"}{
                #class icefall_crumble_tracker open;
                #math {icefall_crumbled} {$icefall_crumbled + %2};
                #var icefall_crumbled {$icefall_crumbled};
                #math {icefall_crumbled_qty} {$icefall_crumbled_qty + 1};
                #var icefall_crumbled_qty {$icefall_crumbled_qty};
                #showme ADDED: %2 the total is now: $icefall_crumbled;
                #class icefall_crumble_tracker close;
        };
};
#alias {^{showcrumbles|icefall crumbles|crumbles}$}{
        #format {number} {%g} {$icefall_crumbled};
        #showme Earned $number gold from crumbles from $icefall_crumbled_qty crumbles in icefall since 1/5/201$
        #math {number} {$icefall_crumbled / 2};
        #format {number} {%g} {$number};
        #showme Half that is $number gold;
        #showme I figure at 4.5M per Icefall point I break even at 337,500,000 gold;
};
#alias {Save_Crumbles}{
        #nop save crumbes every 60 seconds;
        #delay 60 {Save_Crumbles};
        #class icefall_crumble_tracker write {$dirscripts/savedata/icefallcrumblesdata.tin};
        SendTracker Crumbles saved this is in icefall_crumble_tracker.tt eventually can remove this reminder;
};
Save_Crumbles;
#class icefall_crumble_tracker close



Am I doing something wrong, or is #math just not supposed to update the variables? Oddly when I viewed the variables it would show the correct values, and the message saying they were saved fired...it just never updated the file...I just tried a whole bunch of things, like permissions, rewriting, before I just added the #var lines and it worked....
Back to top
View user's profile Send private message
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3818

PostPosted: Tue Jan 09, 2018 8:05 pm    Post subject: Reply with quote

Yes, you need to define the variables while the class is opened for them to be added to the class. It's theoretically possible to auto-assign, but it would be really annoying in cases where you don't want that to happen.

Also keep in mind the class is automatically closed when you use:

Code:

#class icefall_crumble_tracker read {$dirscripts/savedata/icefallcrumblesdata.tin};


It's mentioned in the help file. You would want to simply use:
Code:

#read {$dirscripts/savedata/icefallcrumblesdata.tin};


If the icefall_crumble_tracker class is opened during the #read everything in the file will be added to the class.


I'll try to fix this behavior and make class behave a little more predictable one day.
Back to top
View user's profile Send private message Send e-mail
new_to_tin_tin



Joined: 05 Jan 2011
Posts: 38

PostPosted: Wed Jan 10, 2018 6:18 pm    Post subject: Reply with quote

Scandum wrote:
Yes, you need to define the variables while the class is opened for them to be added to the class.


I guess I thought that this is what I was doing with the opening code:

Code:
#class icefall_crumble_tracker open;
#var {icefall_crumbled} {0};
#var {icefall_crumbled_qty} {0};


And that once I did that, the variable would always be part of that class....so writing later would write the latest values of those variables.

I guess maybe I shouldn't care, this code works, but I always have trouble with classes and writing vars, especially the initial values...

I guess I'm wondering what is the idea way to do this, do I have to open/close the class everytime I access the variable? Update the variable? Save the variable?
Back to top
View user's profile Send private message
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3818

PostPosted: Wed Jan 10, 2018 11:08 pm    Post subject: Reply with quote

new_to_tin_tin wrote:

I guess I thought that this is what I was doing with the opening code:

Code:
#class icefall_crumble_tracker open;
#var {icefall_crumbled} {0};
#var {icefall_crumbled_qty} {0};


And that once I did that, the variable would always be part of that class....so writing later would write the latest values of those variables.

Correct.

Similarly if a variable is classless it will remain classless.

What I tried to point out was that after using "#class icefall_crumble_tracker read" the class is automatically closed. Let me demonstrate:

#class example open
#CLASS {example} HAS BEEN OPENED.
#class example read example.tin
#CLASS {example} IS ALREADY OPENED.
#READ {example.tin} - FILE NOT FOUND.
#CLASS {example} HAS BEEN CLOSED.
#var example 1
#OK. VARIABLE {example} HAS BEEN SET TO {1}.
#class
example 0 CLOSED

new_to_tin_tin wrote:

I guess I'm wondering what is the idea way to do this, do I have to open/close the class everytime I access the variable? Update the variable? Save the variable?

The main purpose of classes is to use #class write to save specific variables to file and to use #class kill.

So if you just want to save those two variables you would put the following in the file.

Code:

#class icefall_crumble_tracker open;
#var {icefall_crumbled} {0};
#var {icefall_crumbled_qty} {0};
#class icefall_crumble_tracker close;


After that your code would simply use #class icefall_crumble_tracker read to load, and #class icefall_crumble_tracker write to save.

The actions and aliases aren't required to be part of the class, unless you want to add them so you can use #class icefall_crumble_tracker kill to disable the tracker.
Back to top
View user's profile Send private message Send e-mail
riper



Joined: 24 Jan 2018
Posts: 15

PostPosted: Tue Jan 30, 2018 8:52 am    Post subject: Reply with quote

Scandum wrote:


I'll try to fix this behavior and make class behave a little more predictable one day.


Glad to see you have interesting on this,even I think class good enough now.
and maybe the #class can be temporary disable ?
expecting.... Embarassed
_________________
TinTin Newbie
Back to top
View user's profile Send private message
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3818

PostPosted: Tue Jan 30, 2018 8:21 pm    Post subject: Reply with quote

riper wrote:

Glad to see you have interesting on this,even I think class good enough now.
and maybe the #class can be temporary disable ?
expecting.... Embarassed

It's often been requested, but it's more complicated than it sounds.

You can use #class kill and #class read to (temporarily) disable and enable a class.
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> Script Help All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Get TinTin++ Mud Client at SourceForge.net. Fast, secure and Free Open Source software downloads Get TinTin++ Mud Client at SourceForge.net. Fast, secure and Free Open Source software downloads
TinTin++ Homepage

Powered by phpBB © 2001, 2002 phpBB Group