Posted: 22nd Jun 2007 11:09
Ok, new problem. I was playing about with scripting and other file related stuff and got stuck.

An example:
+ Code Snippet
//text fill//
[apple]:identity_immunities
inv_name    = "Apple"
cost        = 2

weight      = 0.75
addweight   = 0.2

restore     = 2

[orange]:identity_immunities
inv_name    = "Orange"
cost        = 1

weight      = 0.5

restore     = 1.5


If anyones tried modding Stalker this will look formiliar. I'm trying to put them into array, inside the brackets is the id name and you can guess the others. I need to get the id name and anything before the next id name, how? Cheers.
Posted: 22nd Jun 2007 22:32
Sasuke, I had thought that someone else would grab this one; lots of people using scripting around here, but they seem to be using 3rd party plug-ins.

Parsing is usually pretty specific to the application at hand. Your items are delimited by the [itemname] field. Is it correct in your example that oranges do not have an addweight member? If so, then your immunities bit isn't fixed, which is a little more complicated; usually they look like database entries where they are all the same.

In this case the delimiter is the [ character, it marks the beginning of the place where you are going to want to extract your values. I have some parsing code written, its pretty simple - I am sure you could write it better than I did!

Anyway, if it is something you'd rather not work on now, I could work more on my own parsing code, and see how it could do this job for you. Let me know what you think about this.

btw, I liked your contributions in that RPG thread; you really took that ball and ran with it! That is why I occasionally enter your threads, and make silly comments - I think you are doing the 'good work', and if I can help you in any way - I want to do that.

Cheers, mate.
Posted: 22nd Jun 2007 22:45
I thought evryone would be fed up me saying "use LUA" by now thats why i didn't answer

http://darkbasicpro.thegamecreators.com/?f=lua

if youu think you can make a better scripting system that a team of brazilians have been working on since 1993 the youu better start with this example...

+ Code Snippet
REM Project: file in out
REM Created: 31/12/2006 22:18:33
REM
REM ***** Main Source File *****
REM
type HealthPack
 File as string
 x as float
 y as float
 z as float
 Rotate as byte
endtype

dim Item(100) as HealthPack

Item(1).File="HealthPack.x"
Item(1).x=223
Item(1).y=223
Item(1).z=0
Item(1).Rotate=1

Item(2).File="AmmoClip.x"
Item(2).x=127
Item(2).y=340
Item(2).z=20
Item(2).Rotate=1

Item(3).File="StopSign.x"
Item(3).x=427
Item(3).y=140
Item(3).z=0
Item(3).Rotate=0

` Check for the data file and delete it
`  In case you want to edit the array and re-run it
if file exist("TestData.dat")
 delete file "TestData.dat"
endif

` Save the data
open to write 1,"TestData.dat"
for t=1 to 3
 write string 1,Item(t).File
 write float 1,Item(t).x
 write float 1,Item(t).y
 write float 1,Item(t).z
 write byte 1,Item(t).Rotate
next t
close file 1

` Clear the data
for t=1 to 3
 Item(t).File=""
 Item(t).x=0
 Item(t).y=0
 Item(t).z=0
 Item(t).Rotate=0
next t

` Show the data (to show that the array is empty)
print "Data cleared"
print ""
for t=1 to 3
 print "Item("+str$(t)+")"
 print " Filename = "+Item(t).File
 print " x coordinate = "+str$(Item(t).x)
 print " y coordinate = "+str$(Item(t).y)
 print " z coordinate = "+str$(Item(t).z)
 print " Rotate = "+str$(Item(t).Rotate)
 print ""
 print ""
next t

wait key

` Read the data
open to read 1,"TestData.dat"
for t=1 to 3
 read string 1,Item(t).File
 read float 1,Item(t).x
 read float 1,Item(t).y
 read float 1,Item(t).z
 read byte 1,Item(t).Rotate
next t
close file 1

` Show the data (after its been loaded from the file)
cls
print "Data loaded from file."
print ""
for t=1 to 3
 print "Item("+str$(t)+")"
 print " Filename = "+Item(t).File
 print " x coordinate = "+str$(Item(t).x)
 print " y coordinate = "+str$(Item(t).y)
 print " z coordinate = "+str$(Item(t).z)
 print " Rotate = "+str$(Item(t).Rotate)
 print ""
 print ""
next t

wait key
Posted: 22nd Jun 2007 23:12
GatorHex, I was thinking of you and LUA already...just didn't want to speak for you!!
Posted: 22nd Jun 2007 23:36
You can use mine for free (when it's done )

Data can be stored like this:

+ Code Snippet
tree = [

    var type = "Apple";

    fruit_types = [

        fruit1 = [
            var name = "Fuji";
            var colour = "red";
        ]

        fruit2 = [
            var name = "Granny Smiths";
            var colour = "green";
        ]

    ]

]



Heheheh.
Posted: 22nd Jun 2007 23:41
Lua does more than just scripts it lets youu take you code outside the compiled exe so you change things like monster AI without having to recompile.

Lua looks like this and it's working right now Muhahaha!

[simple lua]
playerName = "Kyro"
level = 10
maxHP = 80


[array lua]
world = {}
world[1] = {}
world[1][1] = {objectType = 1,scale = 4,x = 600.0,y = 22.0,z = 700.0}
world[1][2] = {objectType = 1,scale = 4,x = 1300.0,y = 22.0,z = 600.0}
world[1][3] = {objectType = 1,scale = 4,x = 1500.0,y = 22.0,z = 1500.0}
world[1][4] = {objectType = 1,scale = 4,x = 700.0,y = 22.0,z = 1500.0}
world[1][5] = {objectType = 2,scale = 20,x = 1035.0,y = 21.0,z = 570.0}


[AI Lua]
oldTimer = 0
function moveAmazon (objnum,timer,dist)

monsterName = "Amazon"
attackDistance = 3
moveSpeed = 0.2
attackStrength = 10
-- 1000 = 1 second
attackTimer = 2*1000


-- Get the position of the camera
cx,cy,cz = CamInfo()

-- Keep the Amazon on the floor
cy = 0

-- Move the Amazon if she is not yet at the camera
if dist > attackDistance then
PointObject(objnum,cx,cy,cz)
MoveObject(objnum,moveSpeed)
else
-- Do an attack if we are at the camera position and the timer allows it
if timer > (oldTimer + attackTimer) then
oldTimer = timer
return attackStrength,monsterName
else
return 0,monsterName
end
end

end
Posted: 23rd Jun 2007 0:00
Mine can have control too you know

+ Code Snippet
//Control AI
function controlAI(var spd, var turn)
{
    
    //Angle
    var ang;
    
    //Randomize
    ang = ang + rnd(turn);
    
    //Coords
    var x;
    var z;
    
    //Move
    if (rnd(1) == 1)
    {
        x = x + sin(ang) * spd;
        z = z + cos(ang) * spd;
    }
    
    //Update
    positionObject(1, x, 0, z);
    yrotateObject(1, ang);
    
    
}


//Main
function main()
{
    
    //Main loop
    do
    {
        
        //Control AI(speed, turn value)
        controlAI(5.0, 2.0);
        
    }
    
}



That's just off the top of my head. Obviously it wont work properly because variables ang, x and z arent initialized, but it proves that it can be done.. so ha!
Posted: 23rd Jun 2007 0:01
LUA is a free if youur using C++ anyway, so youu could just written a DBP front end to it. http://www.lua.org Why re-invent the wheel? double ha!
Posted: 23rd Jun 2007 0:21
Why re-invent the wheel?

Because customized wheels are always the coolest, aha!

Besides, as much as I can, I try to use my own stuff. I obviously cant help using C++ and stuff, but more simple things I don't like to copy.
Posted: 23rd Jun 2007 0:49
Wow, loged off for a minute, and theres alot of posts. Anyway, I should of been more specific. For each item you can add varous elements, you could even turn and orange into ammo or a weapon just by adding an item type element. And just as I was writing this I figured it out, ha.

jinzai, thanks for the support, I didn't think I made that much of a contribution.
GatorHex, I like to create my own firsts so I can learn whats involved than using plugin, but in the end if mines not up to scratch i'll take a look into LUA.
Zotoaster, are be looking in to yours when it's done.

Thanks Guys.