Variable/Maths system implementation

Blitz3D Forums/Blitz3D Programming/Variable/Maths system implementation

Damien Sturdy(Posted 2004) [#1]
Hey peeps..
I posted this a while ago but cocked up the Topic title....
Heres what i had to say:

Just need to get some ideas on how to implement Maths and Variables into my script engine?

Ive got the command set in, and got a script system very similar to that of the God Mode in Die Hard Trilogy for those who played it...

Now, ive tried getting maths in but i couldnt get any results;- ive since stripped the maths and variable system out to start again..

So, What techniques/routines would i use to implement these? any code snippets?





Im posting again in case the whole "hey peeps" topic title did peoples head in and they ignored it.
If of course you ignored it for another reason, feel free to ignore this too!

Cheers....


Rob Farley(Posted 2004) [#2]
I would suggest having a type:
Type ScriptVar
Field Name
Field Value
End Type

Then in your script engine:
Peanut = 10

Would create a ScriptVar with Name of Peanut and a Value of 10.

You'd create a function called GetScriptVarValue that returns the value of a VarName and a SetScriptVarValue that checks to see if it already exists, if not create it.

All this code is off the top of my head and totally untested! Expand on this general theme to end up with all the stuff you need.
Function GetScriptVarValue(Name$)
for v.scriptvar = each scriptvar
if v\name = name then return v\value
next
end function

Function SetScriptVarValue(Name$,value)
for v.scriptvar = each scriptvar
if v\name = name then v\value = value:return true
next
v.scriptvar = new scriptvar
v\name = name
v\value = value
end function



Bot Builder(Posted 2004) [#3]
I've done a math thingie in blitz... This is an old ver. newere ones included stuff like if print, vars, etc but i redesigned since it started getting unwieldy, and ive stopped blitzen:



Rather hard to follow since i was doing everything in banks without using text since it was designed as the beginning of a tokenizer for an interpreter. Actually, this isnt too far off from a full interpreter.

As far as variables, i had an array for each variable type stored, each with as many elements as required by the program. Then, in the tokenized form of the program, the index and type of variable is given.

Oh, and my method for tokenizing math expressions with order of operations and parenthesis is explained in the "Converting from infix notation" section I added to a wikipedia article.


Damien Sturdy(Posted 2004) [#4]
cheers for posting...i could and have before easily done varibale implementation via types- is there no quicker way?

BotBuilder; how would i implement this? im not on my coding machine just yet- looks simple enough to put in. Im not loking to have to understand it, just put it in and know it works... or an idea as to where i could start writing one...

Il give that one a go later on. Would you mind me using it?