Modding, Mission Design, and Coding > The Scripting Workshop

Well that was kinda depressing

(1/3) > >>

Vasudan Admiral:
Ok, so I decided I was gonna try and write up some simple scripts for Black Wolf to Fred with.  I thought I'd start with a simplistic gravity function to test with. Four and a half intensely frustrating hours later, I hadn't achieved a thing except crashes with increasingly cryptic errors.

Along the way I decided to try using a script WMC posted a long time ago here: http://www.hard-light.net/forums/index.php/topic,39161.msg796489.html#msg796489 which was meant to just shift the radar along when 1 was pressed in game.
It didn't work at all in the latest build, so I thought I'd see if I could update it with new syntaxes based on the generated scripting.html. An hour or so later, I'd had to delete the FRED variable because of a weird "( near <eof>" error, rearrange the SEXP so it didn't need to return anything because that resulted in some sort of "userdata, expected number" error, add square brackets around the script-eval-num call because it didn't like it otherwise and rewrite the function because mn.getShipByName and ma.newVector no longer existed.

After all that the only thing that happened was a once per second tiny shift in the radar dish that crashed the game when the fenris exploded. :\

Giving up on that, I decided to try and adapt this...semi working.... script to just shift the player down whenever 1 was pressed

Ever more cryptic error after after cryptic error later, I'd chopped the script down to a barebones of:


--- Code: ---#Global Hooks
$GameInit: [
Gravity = function()
    theship = mn.Ships[0]
    theship.Position = theship.Position + ba.createVector(0, -10, 0)
end
]
#End
--- End code ---

Which just crashes as soon as you press 1 in game with this error:

LUA ERROR: attempt to call a string value

LUA Debug:
------------------------------------------------------------------
Name:      (null)
Name of:   
Function type:   C
Defined on:   -1
Upvalues:   0

Source:      =[C]
Short source:   [C]
Current line:   -1


I still haven't a clue where in those 4 lines of code something is going wrong. :(

Wanderer:
For first.. All lua indexes start at 1 instead of 0
Second.. You still need to call that function in simulation hook

In addition using position data to simulate anything tends to break the collision code.

This should work on recent head branch builds and gives 'gravity' to players wingman

--- Code: ---#Global Hooks

$Simulation: [

for u = 1, #mn.Ships do
   objectShip = mn.Ships[u]
   stringShipName = objectShip.Name
   if stringShipName == "Alpha 2" then
      vectorGravity = objectShip.Physics.Velocity
      vectorGravity[2] = vectorGravity[2] - 10
      objectShip.Physics.Velocity = vectorGravity
   end
end

]

#End
--- End code ---

Vasudan Admiral:

--- Quote from: Wanderer on July 10, 2007, 01:01:04 am ---For first.. All lua indexes start at 1 instead of 0
--- End quote ---
Yeah I had it at 1 for that reason to begin with, but that didn't appear to do anything in mission - I assumed that maybe it was moving/trying to move something else, and also noticed that the mn.Ships function was said to use the index of the ship in Fred - which has the player as 0. :)


--- Quote from: Wanderer on July 10, 2007, 01:01:04 am ---Second.. You still need to call that function in simulation hook
--- End quote ---
I do? Why's that? Part of the reason for this experiment was to try and figure out a way to build up a library of functions that could be called from Fred when needed. From what I gathered, simulation doesn't do that and instead is kinda just 'always on' while in game?


--- Quote from: Wanderer on July 10, 2007, 01:01:04 am ---In addition using position data to simulate anything tends to break the collision code.
--- End quote ---
Ah; in this case I used it because it looked like a nice and easy function, but that's good to know. Thanks. :)


--- Quote from: Wanderer on July 10, 2007, 01:01:04 am ---This should work on recent head branch builds and gives 'gravity' to players wingman

--- Code: ---#Global Hooks

$Simulation: [

for u = 1, #mn.Ships do
   objectShip = mn.Ships[u]
   stringShipName = objectShip.Name
   if stringShipName == "Alpha 2" then
      vectorGravity = objectShip.Physics.Velocity
      vectorGravity[2] = vectorGravity[2] - 10
      objectShip.Physics.Velocity = vectorGravity
   end
end

]

#End
--- End code ---

--- End quote ---
Ok, I'll give that a go when I get home tonight, thanks again. :)

Wanderer:
Well.. If you create functions in gameinit you still have to call them in simulation (or in some another hook).. Sort of like you have exe files on your computer but they wont actually do anything unless you run them. So you can create a library of functions in gameinit but they will just sit idle unless called somewhere.

Vasudan Admiral:
Ok, even if I copy & paste that code as my entire scripting table, I still get:

LUA ERROR: attempt to call a string value

upon committing to any mission.
So it turns out it isn't a problem with my above code (not counting the "mn.Ships[0]" thing, because I *had* previously tried it with a 1) but is something else entirely.

What that something is though, I don't know. I'll try a clean install and an older build in the builds of interest thread to start with.

Navigation

[0] Message Index

[#] Next page

Go to full version