View unanswered posts | View active topics It is currently Fri Dec 27, 2024 6:50 am



Reply to topic  [ 10 posts ] 
 Yet another insomia driven discovery. 
Author Message
User avatar

Joined: Tue Nov 06, 2007 6:58 am
Posts: 2054
Reply with quote
Post Yet another insomia driven discovery.
PresetName and GoldCost can be altered from lua.
And they stay that way.

Free variable storage space, anyone?


Fri Aug 14, 2009 8:57 am
Profile
User avatar

Joined: Sun Jul 13, 2008 9:57 am
Posts: 4886
Location: some compy
Reply with quote
Post Re: Yet another insomia driven discovery.
be sure to use copyofs :3


Fri Aug 14, 2009 10:25 am
Profile WWW
User avatar

Joined: Mon Jun 30, 2008 9:13 pm
Posts: 499
Location: Finland
Reply with quote
Post Re: Yet another insomia driven discovery.
Staying doesn't mean the costs changing in the buy menu though. Just handy semi-non-global variables.


Fri Aug 14, 2009 12:22 pm
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: Yet another insomia driven discovery.
Kyred told me about this a few days ago.

Also: for testing purposes, someone try and change the presetname and instancename of something that's defined in-.ini as InstanceName, not PresetName.


Fri Aug 14, 2009 6:27 pm
Profile
DRL Developer
DRL Developer
User avatar

Joined: Wed Dec 13, 2006 5:27 am
Posts: 3138
Location: A little south and a lot west of Moscow
Reply with quote
Post Re: Yet another insomia driven discovery.
I used PresetName changing for the hoverboards and for p3lb0x's MC3 contest entry (the crafts dwarf).
I didn't know GoldCost could be changed, though. I could swear I remember that not working.


Fri Aug 14, 2009 8:09 pm
Profile WWW
User avatar

Joined: Sun May 31, 2009 1:04 am
Posts: 308
Reply with quote
Post Re: Yet another insomia driven discovery.
I have been using changes the PresetName extensively with the Dummy Factory. Using the new PresetName as a key/index for global tables is very useful indeed.


Sat Aug 15, 2009 4:28 am
Profile
User avatar

Joined: Tue Nov 06, 2007 6:58 am
Posts: 2054
Reply with quote
Post Re: Yet another insomia driven discovery.
Indeed. That was exactly what I was thinking of.


Sat Aug 15, 2009 5:34 am
Profile
DRL Developer
DRL Developer
User avatar

Joined: Thu Jun 11, 2009 2:34 pm
Posts: 966
Location: Moscow, Russia
Reply with quote
Post Re: Yet another insomia driven discovery.
I tried to save some info in GoldCost but it seems that CC just resets it's state to nil every time. I try to get stored value from GoldCost and receive nil on every Update(self).


Thu Aug 20, 2009 9:09 pm
Profile
DRL Developer
DRL Developer
User avatar

Joined: Wed Dec 13, 2006 5:27 am
Posts: 3138
Location: A little south and a lot west of Moscow
Reply with quote
Post Re: Yet another insomia driven discovery.
Simple tutorial on storing and retrieving data in a PresetName:
Let's say you have an object that creates another object, and you want it to home in on a certain position that can only be retrieved from the first object. This means you have to pass on a vector coordinate. Storing a variable in the newly-created object won't work, as it will be reset to nil next update. The only way to do so is to use PresetName.
First of all, we store the vector values in the new object's PresetName. Make sure to take this step BEFORE adding the object with MovableMan:
Code:
object.PresetName = foo.X .. "," .. foo.Y;

Assuming the coordinates are {500,200}, this is storing them as "500 200".
Now we have to retrieve them in the new object's Create event:
Code:
   for num in string.gmatch(self.PresetName, "%d+") do
      if i == 0 then
         self.bar.X = tonumber(num);
      else
         self.bar.Y = tonumber(num);
      end
      i = i + 1;
   end

What we're doing here is using string.gmatch to return a list of strings matching a pattern. In this case, the pattern "%d+". "%d" searches for digits, and the "+" tells it to look for 1 or more repetitions of that type (in this case digits) after the first one is found. We then cycle through the loop using a counter. If it's the first loop, we take the X coordinate using tonumber (as gmatch returns a string). If it's the second loop, we take the Y coordinate.
It should be fairly easy to apply this to your own needs. If you want more info on patterns, this is a good link: http://www.lua.org/pil/20.2.html


Thu Aug 20, 2009 10:23 pm
Profile WWW
DRL Developer
DRL Developer
User avatar

Joined: Thu Jun 11, 2009 2:34 pm
Posts: 966
Location: Moscow, Russia
Reply with quote
Post Re: Yet another insomia driven discovery.
I had to store a single number so I used only tonumber\tostring, but your tutorial is more complete, thanks.


Thu Aug 20, 2009 10:35 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 10 posts ] 

Who is online

Users browsing this forum: No registered users


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 post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.034s | 13 Queries | GZIP : Off ]