|
-
Aug 16th, 2001, 09:13 PM
#1
Thread Starter
Lively Member
countin charactors
K im makin a program that counts charactors in other program like scripts. like it would be a command like this
SetThingFlags(victim, 0x12349);
and it would have 3 type one charactors 1 type 2 charactor and 1 type three charactor.
like sethingflags, victim, 0x12349 would be type one
() would be type 2 and
; would be typ three
Anywho, im trying to find out how to seperate and count the type one charactors. I have the type 2 and three down but dont know how to get the type 1
-
Aug 16th, 2001, 09:54 PM
#2
You didn't say how this data is laid out or anything but try counting backward from the ( until you get to the begining of the line.
-
Aug 17th, 2001, 03:15 AM
#3
Retired VBF Adm1nistrator
Yes as we dont know an awful lot about what you're trying to do, I can only throw in a few suggestions.
Use InStr(), Left(), Mid(), Right() and Split()
The above functions would be the most common string manipulation functions. I would imagine a combination of them would suffice.
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Aug 17th, 2001, 07:08 PM
#4
Thread Starter
Lively Member
Ok. Sorry I was not to specific but anyways, there are these scripts. Cogs as they are called, for a game. Now im making a program that will tell you the charactor numbers for a user looking at cogs.
now there are 2 diffrent types of caractor that the game looks at
one is a set of caractors that basicly define what the script is doing and what it is applying it to. the second one (witch I was able to do) was mislanious things like =, *, (), &, /, - and so on and so forth.
now you would have a command that would go like this
SetActorFlags(Player, 0x8);
See the SetActorFlags, Player, and 0x8 would all be type 1 charactors. the () would be type two, and ; would tell the program that one line is there. what im trying to do is make it so it will be able to count the SetActorFlags(player, 0x8); the thing is though these values could be anything, such as ClearActorFlags(therealvictime, 0x4830); and yet that one would have the same charactor count as the first one. what im thinking of doing is making it so that it will look at the script and count the commas and + 1 to get the charactor counts. the problem with that though is you have scripts like this
CreateThingNR(thing, Vel(GetThingSector(victim), GetThingPos(victim), GetSenderRef()));
hopefully this explanes what im trying to do a little better
-
Aug 17th, 2001, 09:40 PM
#5
Thread Starter
Lively Member
-
Aug 20th, 2001, 02:01 AM
#6
Retired VBF Adm1nistrator
Do you have a sample script ?
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Aug 20th, 2001, 10:51 AM
#7
Thread Starter
Lively Member
Certanly
Right here is a script
# WEAP_FISTS.COG
#
# WEAPON 1 Script - Fists
#
# The primary fire for is a punch with the left fist and then the right fist.
#
# - Not affected by MagSealed sectors/surfaces.
#
# [YB & CYW]
#
# (C) 1997 LucasArts Entertainment Co. All Rights Reserved
# (LucasArts has givin permsion for anyone to edit there cogs so
# Long as they dont sell them)
symbols // Now This stuff below here Im not counting
model povModel=fistv.3do
model weaponMesh=fistg.3do
keyframe mountAnim=FistVmnt.key local
keyframe dismountAnim=FistVdis.key local
keyframe povfireAnim1=FistVl.key local
keyframe povfireAnim2=FistVr.key local
keyframe holsterAnim=kyhlstr.key local
sound fireSound1=SwingFist01.wav local
sound fireSound2=SwingFist04.wav local
template projectile=+punch local
thing player local
flex leftWait=0.25 local
flex rightWait=0.25 local
flex mountWait local
flex holsterWait local
int trackID=-1 local
int nextAnim=0 local
int holsterTrack local
message startup
message activated
message deactivated
message selected
message deselected
#message newplayer
message autoselect
message fire
message timer
end // All the way to here I would not count
# ========================================================================================
code
startup:
player = jkGetLocalPlayer();
// Setup delays.
leftWait = GetKeyLen(povfireAnim1);
rightWait = GetKeyLen(povfireAnim2);
mountWait = GetKeyLen(mountAnim);
Return;
# ........................................................................................
fire:
// Check that the player is still alive.
if(GetThingHealth(player) <= 0)
{
Return;
}
// Alternate fists.
if(nextAnim == 0)
{
SetPOVShake('-0.01 -.01 0.0', '1.0 0.0 0.0', .05, 80.0);
PlaySoundThing(fireSound1, player, 1.0, 0.5, 2.5, 0x80);
FireProjectile(player, projectile, -1, 8, '-0.02 0.03 0', '0 0 0', 1.0, 0, 0.0, 0.0);
SetFireWait(player, leftWait);
}
else
{
SetPOVShake('0.01 -.01 0.0', '1.0 0.0 0.0', .05, 80.0);
PlaySoundThing(fireSound1, player, 1.0, 0.5, 2.5, 0x80);
FireProjectile(player, projectile, -1, 18, '0.02 0.03 0', '0 0 0', 1.0, 0, 0.0, 0.0);
SetFireWait(player, rightWait);
}
jkPlayPOVKey(player, povfireAnim1[nextAnim], 1, 0x0a);
nextAnim = 1-nextAnim;
Return;
# ........................................................................................
activated:
player = GetSourceRef();
mode = GetSenderRef();
jkSetWaggle(player, '0.0 0.0 0.0', 0);
ActivateWeapon( player, leftWait, mode );
Return;
# ........................................................................................
deactivated:
player = GetSourceRef();
mode = GetSenderRef();
jkSetWaggle(player, '10.0 7.0 0.0', 350);
DeactivateWeapon( player, mode );
Return;
# ........................................................................................
selected:
player = GetSourceRef();
PlayMode(player, 40);
// Setup the meshes and models.
jkSetPOVModel(player, povModel);
jkSetWeaponMesh(player, weaponMesh);
SetArmedMode(player, 0);
jkSetWaggle(player, '10.0 7.0 0.0', 350);
// Play the animation (NOLOOP + UNIQUE + ENDPAUSE).
// The animation is held at the last frame after it is played.
trackID = jkPlayPOVKey(player, mountAnim, 0, 20);
SetMountWait(player, mountWait);
// Clear saber flags, and allow activation of the weapon
jkClearFlags(player, 0x5);
SetCurWeapon(player, 1);
Return;
# ........................................................................................
deselected:
player = GetSourceRef();
// Stop the mount's last frame animation, and play the dismount.
jkPlayPOVKey(player, dismountAnim, 0, 18);
holsterWait = GetKeyLen(holsterAnim);
SetMountWait(player, holsterWait);
holsterTrack = PlayKey(player, holsterAnim, 1, 0x4);
SetTimerEx(holsterWait, 2, 0.0, 0.0);
if (trackID != -1)
{
jkStopPOVKey(player, trackID, 0);
trackID = -1;
}
jkSetWaggle(player, '0.0 0.0 0.0', 0);
Return;
# ........................................................................................
//newplayer:
// player = GetSourceRef();
//
// // Make sure that if the player is respawning, the old mount isn't playing anymore.
// if (trackID != -1)
// {
// jkStopPOVKey(player, trackID, 0);
// trackID = -1;
// }
//
// Return;
# ........................................................................................
autoselect:
// Select fists when out of everything else...
ReturnEx(100.0);
Return;
# ........................................................................................
timer:
StopKey(player, holsterTrack, 0.0);
Return;
end
Now I only bolded those two section so you could get the point one what Im trying to count, (everything I bolded would be 1 added to the charactor count) now the problem I run into is that everything Im counting can have any numbers of letters or numbers in it and it could end up being somthing like this
if(GetThingHealth(GetThingParent(GetThingRef())) != 1){dostuff}
any suggestions?
-
Aug 20th, 2001, 11:02 AM
#8
Retired VBF Adm1nistrator
Well you could use this function I just wrote :
VB Code:
Private Function CharCount(strChar As String, strSearchIn As String) As Long
Dim retVal As Long
If (strSearchIn <> "") Then
Do
DoEvents
If (InStr(strSearchIn, strChar) <> 0) Then
strSearchIn = Replace(strSearchIn, strChar, "", 1, 1)
retVal = retVal + 1
Else
Exit Do
End If
Loop
End If
CharCount = retVal
End Function
And basically just do something like :
VB Code:
Dim strToCheck As String
strToCheck = "if(GetThingHealth(GetThingParent(GetThingRef())) != 1){dostuff} "
MsgBox "Number of functions : " & CharCount("(", strToCheck)
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Aug 20th, 2001, 11:05 AM
#9
Thread Starter
Lively Member
This might even Help
This is a guide to charactor counting, It might help you understand what im trying to do
That said, the rest of this will focus on character counting in Jedi Knight Cogs. This should be rather easy for you to understand but I'm probably giving the majority of you that will read this way too much credit (as I've already told most people with brains about this stuff).
You all probably learned that something like.....
SetActorFlags(victim, 0x400000);
is 4 characters. This is true to some extents and not to others. You do have 4 characters in this line but you have 2 different TYPES of characters. I refer to them as types 1-3. This line contains 3 type 1 characters, and 1 type 2 character.
SetActorFlags, victim, 0x400000.....are the type 1 characters
().....is the type 2 character
Jedi Knight not only keeps a total character count but also seems to count the different type of characters.
ok analogy time i have 5 apples and 6 pears, i have 11 total, my teacher wants me to keep the same count overall, and the same count of each type. now that teacher only bought those green apples and i hate them so i swapped them for plain old red ones. now i've changed one of the character types but i changed it to something else of the same type so i kept it the same and that teacher stayed happy. then i tried to go with 6 apples and 5 pears but wait, that pissed her off and i didn't get away with it.
TYPE 1 CHARACTERS
-----------------
SetActorFlags, 1, 0x1, GetSenderID, player, victim
these are your most common type.
TYPE 2 CHARACTERS
-----------------
(), *, &, +, -, !, /, |
TYPE 3 CHARACTERS
-----------------
if, while, for
___________________________________________
....one last thing i should point out though......
! = ()........NOT ! = (
1 pair of parenthesis is the same as an exclamation mark so dont let something dumb like that trick you.
-
Aug 20th, 2001, 11:07 AM
#10
Thread Starter
Lively Member
btw, that last post was written but not submitted before you. but anyways. Tnx for not loosing attention
-
Aug 20th, 2001, 11:13 AM
#11
Retired VBF Adm1nistrator
The reason it probably confuses people is because of the word character. People would naturally think that a character is ... well ... a single character. Like a letter or a number or a sumbol.
But in this case, a character is something completely different.
There was also very little to go on to make an educated guess as to what characters are.... and more importantly, a lack of an exhausted list of what the different characters can be ...
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Aug 20th, 2001, 11:13 AM
#12
Thread Starter
Lively Member
hummm
that last thing you wrote does not quite work out. It does do somthing I need it to do, and thnx for doing that. but If i had somthing like SetThingFlags(victim, 0x2003); it would return 1 only, where as there are 3 charactors in there. SetThingFlags, Victim, 0x2003 But anyways Thnx for helping. Ill keep on trying at it. [edit] I look stupid again posting like this. But anyways ill keep that in mind that now everyone knows what im thinking. tnx [/edit]
-
Aug 20th, 2001, 11:16 AM
#13
Retired VBF Adm1nistrator
Well what you could do is as follows,
Use my function, and then also use the Split() function on the String between the paranthesis using "," as the delimeter, and get the UBound() of that array.
Then add, and you'd have the number of characters ... in that particular case anyway
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Aug 20th, 2001, 11:29 AM
#14
Retired VBF Adm1nistrator
Another thing, there are probably lots of real smart ways of doing this, but maybe just a bog-standard, nearly dump approach would be easiest.
If you knew what all characters could be, then you could do something like this :
VB Code:
Option Explicit
Private toLookFor(0 to 100) As String
Private Sub Form_Load()
toLookFor(0) = "if"
toLookFor(1) = "then"
toLookFor(2) = "else"
toLookFor(3) = "SetActorFlags"
toLookFor(4) = ....
'
'fill in the rest etc.
'
Dim strBlah As String
strBlah = "SetActorFlags(..........."
MsgBox("Number of characters in strBlah : " & DoCharactersLookup(strBlah))
End Sub
Private Function DoCharactersLookup(strBlah As String) As Long
Dim retVal As Long
For i = 0 To 100
retVal = retVal + CharCount(toLookFor(i), strBlah)
Next i
DoCharactersLookup = retVal
End Function
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Aug 20th, 2001, 02:29 PM
#15
Thread Starter
Lively Member
ahh thats the thing, I do know what all the charactors are. http://www.code-alliance.com/~editor...cs/jkspecs.htm
But there are over a hundred of them so It is alittle hard. plus there is nothing restricting the thing to have somthing like X(b, a); cause that would still = 3 and yet, it would not do anything, Some could put billyistheace(herewherever, youwant); and it would still = 3 yet, do nothing
-
Aug 23rd, 2001, 02:24 AM
#16
Retired VBF Adm1nistrator
Okay so then you add in a little more smarts.
If it sees :
Code:
someString(someOtherString1, someOtherString2)
Then it knows thats 3.
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|