View unanswered posts | View active topics It is currently Sat Dec 28, 2024 5:19 pm



Reply to topic  [ 15 posts ] 
 Detecting specific characters in a line of text? 
Author Message
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post Detecting specific characters in a line of text?
What I'm trying to do is get Lua to detect characters in a line of text. For example, Let's say I have:

local text = "This is an example";

And I can use some sort of function:

local textgetter = text:GetCharacter(1);
local textgetterB = text:GetCharacter(2);
local textgetterC = text:GetCharacter(8);

Making (textgetter) be "T", (textgetterB) be "h", and (textgetterC) "(space)". Is there a function like this that exists?

Edit: Also, what are the functions for I/O -
1. Opening a file
2. Reading something from a specific line
3. Getting the total number of lines
4. Writing things to the file/saving


Fri Jan 22, 2010 9:27 pm
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: Detecting specific characters in a line of text?
I realize this is somewhat unhelpful, but it'd probably be pretty useful to look at the official documentation on the string library and the I/O library (chapters 20 and 21, respectively) for some general advice.


Sat Jan 23, 2010 2:04 am
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post Re: Detecting specific characters in a line of text?
They helped a bit, but a little hard to read.

I have another question: Is there a way to detect the net force acting on an MO?


Sun Jan 24, 2010 8:05 pm
Profile
Banned
User avatar

Joined: Tue Feb 27, 2007 4:05 pm
Posts: 2527
Reply with quote
Post Re: Detecting specific characters in a line of text?
I don't know if I like that this game has the ability to open and edit files.


Sun Jan 24, 2010 9:42 pm
Profile YIM
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post Re: Detecting specific characters in a line of text?
I don't think it can get anything outside of the CC folder, but I could be wrong.


Sun Jan 24, 2010 10:27 pm
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: Detecting specific characters in a line of text?
ProjektTHOR wrote:
I don't know if I like that this game has the ability to open and edit files.


yeah it could delete system32 and then you'd be ♥♥♥♥


Mon Jan 25, 2010 2:10 am
Profile
User avatar

Joined: Fri Dec 22, 2006 4:20 am
Posts: 4772
Location: Good news everyone!
Reply with quote
Post Re: Detecting specific characters in a line of text?
Any program can open and edit files.

Its how you get viruses.


Anyhow I think CC can only edit files in the same folder it is.
Worst case scenario is someone writes code to corrupt/delete Base.rte, then you'd have to reinstall.
(Or they can steal your key, but whatever.) :P


Mon Jan 25, 2010 6:40 am
Profile WWW
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post Re: Detecting specific characters in a line of text?
CaveCricket48 wrote:
I have another question: Is there a way to detect the net force acting on an MO?


Mon Jan 25, 2010 7:34 pm
Profile
User avatar

Joined: Mon May 18, 2009 11:48 pm
Posts: 205
Location: The swamps of Stuporia!
Reply with quote
Post Re: Detecting specific characters in a line of text?
CrazyMLC wrote:
Any program can open and edit files.

Its how you get viruses.


Anyhow I think CC can only edit files in the same folder it is.
Worst case scenario is someone writes code to corrupt/delete Base.rte, then you'd have to reinstall.
(Or they can steal your key, but whatever.) :P

The worst Lua virus I've heard of is one made in Garry's Mod that corrupted your addons folder. Correct me if I'm wrong, though.


Wed Mar 03, 2010 12:00 pm
Profile YIM

Joined: Wed Mar 03, 2010 12:28 pm
Posts: 20
Reply with quote
Post Re: Detecting specific characters in a line of text?
AgentBaron wrote:
CrazyMLC wrote:
Any program can open and edit files.

Its how you get viruses.


Anyhow I think CC can only edit files in the same folder it is.
Worst case scenario is someone writes code to corrupt/delete Base.rte, then you'd have to reinstall.
(Or they can steal your key, but whatever.) :P

The worst Lua virus I've heard of is one made in Garry's Mod that corrupted your addons folder. Correct me if I'm wrong, though.


They are properly termed lua viruses in gmod, because they spread from host to client.

In CC, you are actually downloading an archive and extracting it.

It can delete any file on your computer or do anything it would like, there are no limits in CC.


Wed Mar 03, 2010 12:31 pm
Profile
User avatar

Joined: Mon Jun 29, 2009 2:40 am
Posts: 610
Location: Deep below The Map of Mars
Reply with quote
Post Re: Detecting specific characters in a line of text?
CaveCricket48 wrote:
I have another question: Is there a way to detect the net force acting on an MO?
Stop going off topic, and help the man.

I tried to do this a while ago with some really, really retarded methods. If anyone knows how, I want to know as well.


Wed Mar 03, 2010 6:18 pm
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: Detecting specific characters in a line of text?
if by 'force' you actually mean kinetic energy just use KE = mv^2


Thu Mar 04, 2010 3:23 am
Profile

Joined: Wed Mar 03, 2010 12:28 pm
Posts: 20
Reply with quote
Post Re: Detecting specific characters in a line of text?
Does cc actually use that to calculate the kinetic energy?

also wouldn't that only be useful to a modder if they wanted to apply their own physics to an object or something?


Thu Mar 04, 2010 4:07 am
Profile
User avatar

Joined: Sat Nov 03, 2007 9:44 pm
Posts: 1916
Location: Flint Hills
Reply with quote
Post Re: Detecting specific characters in a line of text?
Well assuming CC has anything near an accurate physics engine, (disputable) what you get with that should be at least proportional to the in-game physics.
Although the actual equation is what grif said divided by two, assuming the SI units of Kg, [what cc uses] m/s, [also what cc uses, 1m=20px] and Joules [the derivative unit of those two units, so cc probably uses this too]


But if you actually want the force like you asked for instead of kinetic energy... [they're very different and far from interchangeable]
You could take checks of the velocity and time, [maybe record them in a list or something] and find the acceleration between the two points in time from that.
Vf - Vi = ΔV [CC velocity unit is already m/s]
Tf - Ti = ΔT [you will probably want to convert units from milliseconds to seconds about now]
ΔV/ΔT = a [gonna be m/s² if you converted to seconds]
m * A = ΣFapplied, Joules if you used seconds

One check per sim update could be a limiting factor in your recording though.

And keep in mind gravity. I'm pretty sure you can find the gravity of a scene through Lua (BW:M did this for the zero-g bunker systems], so if you want to find the net force excluding gravity, that's possible.


Last edited by Azukki on Thu Mar 04, 2010 6:14 am, edited 7 times in total.



Thu Mar 04, 2010 4:46 am
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post Re: Detecting specific characters in a line of text?
What I need this for is a better working rope, so if there are 2 objects attached with a rope and the larger of the two pulls, the smaller one will be pulled while the larger slowed down. The function I'm trying to use to apply the force is "target:AddImpulseForce()", so I thought finding a way to check net force would help.

Then I ditched this idea and switched over to using position and velocity to create a rope (as seen in my grappling gun mod) which is great for terrain grappling, but not for 2 moving things.

Grif wrote:
if by 'force' you actually mean kinetic energy just use KE = mv^2

Tried, didn't quite work out for my purposes. (I'm probably be doing something wrong)

Azukki wrote:
Well assuming CC has anything near an accurate physics engine, (disputable) what you get with that should be at least proportional to the in-game physics.
Although the actual equation is what grif said divided by two, assuming SI units.


But if you actually want the force like you asked for instead of something related...
You could take checks of the velocity at a regular rate, [record them in a list or something I guess] you could find the acceleration between any two points in time, and then multiply that by the mass to find the net force that was applied during that time.

One check per sim update could be a limiting factor in your recording though.

Will try sometime, once I finish my current mod I'm working on.


Thu Mar 04, 2010 5:13 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 15 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.041s | 14 Queries | GZIP : Off ]