Author Topic: Well that was kinda depressing  (Read 3635 times)

0 Members and 1 Guest are viewing this topic.

Offline Vasudan Admiral

  • Member
  • 211
    • Twisted Infinities
Well that was kinda depressing
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: [Select]
#Global Hooks
$GameInit: [
Gravity = function()
    theship = mn.Ships[0]
    theship.Position = theship.Position + ba.createVector(0, -10, 0)
end
]
#End

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. :(
Get the 2014 Media VPs and report any bugs you find in them to the FSU Mantis so that we may squish them. || Blender to POF model conversion guide
Twisted Infinities

 

Offline Wanderer

  • Wiki Warrior
  • 211
  • Mostly harmless
Re: Well that was kinda depressing
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: [Select]
#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
Do not meddle in the affairs of coders for they are soggy and hard to light

 

Offline Vasudan Admiral

  • Member
  • 211
    • Twisted Infinities
Re: Well that was kinda depressing
For first.. All lua indexes start at 1 instead of 0
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. :)

Second.. You still need to call that function in simulation hook
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?

In addition using position data to simulate anything tends to break the collision code.
Ah; in this case I used it because it looked like a nice and easy function, but that's good to know. Thanks. :)

This should work on recent head branch builds and gives 'gravity' to players wingman
Code: [Select]
#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
Ok, I'll give that a go when I get home tonight, thanks again. :)
Get the 2014 Media VPs and report any bugs you find in them to the FSU Mantis so that we may squish them. || Blender to POF model conversion guide
Twisted Infinities

 

Offline Wanderer

  • Wiki Warrior
  • 211
  • Mostly harmless
Re: Well that was kinda depressing
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.
Do not meddle in the affairs of coders for they are soggy and hard to light

 

Offline Vasudan Admiral

  • Member
  • 211
    • Twisted Infinities
Re: Well that was kinda depressing
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.
Get the 2014 Media VPs and report any bugs you find in them to the FSU Mantis so that we may squish them. || Blender to POF model conversion guide
Twisted Infinities

 

Offline Wanderer

  • Wiki Warrior
  • 211
  • Mostly harmless
Re: Well that was kinda depressing
Scripting - that i used - works only with unstable branch builds. So are you using 369 builds or unstable (pre-3.7) builds?
Do not meddle in the affairs of coders for they are soggy and hard to light

 

Offline Vasudan Admiral

  • Member
  • 211
    • Twisted Infinities
Re: Well that was kinda depressing
This one: http://www.hard-light.net/forums/index.php/topic,44659.0.html

(first post of the Builds of Interest thread in the scripting subforum)

Edit: Ah, ok, it works with that build with a clean install + media VPs, so something else is mucking it up in my main install...

Edit2: Well, cleaned up and sorted out my tables folder, and now it works too. I don't really see anything in there that should have crashed it, but apparently something did.
Ah well, fixed now. :) Back to ze experiments!
« Last Edit: July 10, 2007, 06:24:53 am by Vasudan Admiral »
Get the 2014 Media VPs and report any bugs you find in them to the FSU Mantis so that we may squish them. || Blender to POF model conversion guide
Twisted Infinities

 

Offline Vasudan Admiral

  • Member
  • 211
    • Twisted Infinities
Re: Well that was kinda depressing
Another question: How do return values work with the script-eval-num?

I'm using this code:
Code: [Select]
#Global Hooks

$GameInit: [
Function1 = function()
return 1
end
]

#End

In conjunction with this SEXP setup:



And it crashes on mission commit with this error:

<UNKNOWN>: Argument 1 is an invalid type 'Userdata'; number expected
Get the 2014 Media VPs and report any bugs you find in them to the FSU Mantis so that we may squish them. || Blender to POF model conversion guide
Twisted Infinities

 

Offline Wanderer

  • Wiki Warrior
  • 211
  • Mostly harmless
Re: Well that was kinda depressing
Got to admit that i have only used 'plain' script-eval... not string or num versions of it.. so no real ideas how to do that..
Do not meddle in the affairs of coders for they are soggy and hard to light

 

Offline WMCoolmon

  • Purveyor of space crack
  • 213
Re: Well that was kinda depressing
Looks like a bug...mantis & assign to me.
-C

 

Offline Vasudan Admiral

  • Member
  • 211
    • Twisted Infinities
Get the 2014 Media VPs and report any bugs you find in them to the FSU Mantis so that we may squish them. || Blender to POF model conversion guide
Twisted Infinities