Data Realms Fan Forums
http://45.55.195.193/

Yet another insomia driven discovery.
http://45.55.195.193/viewtopic.php?f=73&t=16213
Page 1 of 1

Author:  mail2345 [ Fri Aug 14, 2009 8:57 am ]
Post subject:  Yet another insomia driven discovery.

PresetName and GoldCost can be altered from lua.
And they stay that way.

Free variable storage space, anyone?

Author:  Geti [ Fri Aug 14, 2009 10:25 am ]
Post subject:  Re: Yet another insomia driven discovery.

be sure to use copyofs :3

Author:  piipu [ Fri Aug 14, 2009 12:22 pm ]
Post subject:  Re: Yet another insomia driven discovery.

Staying doesn't mean the costs changing in the buy menu though. Just handy semi-non-global variables.

Author:  Grif [ Fri Aug 14, 2009 6:27 pm ]
Post subject:  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.

Author:  TheLastBanana [ Fri Aug 14, 2009 8:09 pm ]
Post subject:  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.

Author:  Kyred [ Sat Aug 15, 2009 4:28 am ]
Post subject:  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.

Author:  mail2345 [ Sat Aug 15, 2009 5:34 am ]
Post subject:  Re: Yet another insomia driven discovery.

Indeed. That was exactly what I was thinking of.

Author:  weegee [ Thu Aug 20, 2009 9:09 pm ]
Post subject:  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).

Author:  TheLastBanana [ Thu Aug 20, 2009 10:23 pm ]
Post subject:  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

Author:  weegee [ Thu Aug 20, 2009 10:35 pm ]
Post subject:  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.

Page 1 of 1 All times are UTC [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/