Moving Jbeam Objects in Scenarios?

Discussion in 'Programming' started by Occam's Razer, Apr 4, 2016.

  1. Occam's Razer

    Occam's Razer
    Expand Collapse

    Joined:
    Aug 7, 2013
    Messages:
    1,152
    I'm looking in to creating some short but very... dynamic(?) scenarios. I'd like to have several vehicles in the scene, but I'm limited by my processor to three, and I imagine there are many persons out there with an even more restrictive situation.

    However, the layout of the scenarios means that there only ever need to be three cars maximum on the screen at any one time, so to make a long post short: Is it possible to reset, reposition, reorient, or perhaps even replace*, a Jbeam object in a currently-running scenario, in realtime, by way of Lua? And if so, how?

    I know the Torque Script means of repositioning an object, but not the Lua one. And even then, it seems like the kind of feature that would be disallowed during a scenario (seeing as this could be achievable by way of the console window, and be used to cheat). I'm not sure if any of this is possible, but it could be a nifty trick to allocate resources if it is.

    *This one is optional, less crucial. I realize that the Jbeam of another new vehicle loading would likely cause some frame-hang, so I would likely use this option sparingly if at all.
     
  2. Scepheo

    Scepheo
    Expand Collapse

    Joined:
    Feb 10, 2015
    Messages:
    601
    One way is to execute TS code with:
    Code:
    TorqueScript.eval('your TS code here')
    race_marker.lua uses this to create, resize and move the checkpoint markers during races.

    There's also some built-in Lua functions (have a look at the wiki for those), but those are a lot more limited in what you can do.
     
    • Like Like x 1
  3. Occam's Razer

    Occam's Razer
    Expand Collapse

    Joined:
    Aug 7, 2013
    Messages:
    1,152
    Thank you, the TorqueScript line got me to getting the lua file situated. Unfortunately, while that line works perfectly in freeroam, the scenario is blacklisted when I attempt to use it. As in, this line:

    Code:
    TorqueScript.eval('clientGroup.getObject(0).player.setTransform("0 0 1 0 0 1 3");')
    works just fine, although it resets, repositions, and reorients the player instead of another vehicle, whereas this line:

    Code:
    TorqueScript.eval('clientGroup.getObject('Prop01').player.setTransform("0 0 1 0 0 1 3");')
    ...causes the scenario to be blacklisted and therefore unplayable. In every other way, the above TS line works as needed in freeplay. Is there some way around this? Or perhaps some other way to identify which vehicle I'm attempting to transform? I tried resetting the getObject number to one or two, to no avail.
     
  4. Scepheo

    Scepheo
    Expand Collapse

    Joined:
    Feb 10, 2015
    Messages:
    601
    Code:
    TorqueScript.eval('objectName.setTransform("0 0 0 0 0 1 0")')
    should just work.

    Edit: I just noticed that you used single quotes around Prop01 instead of double quotes, prematurely terminating the string and rendering the Lua invalid.
     
  5. Occam's Razer

    Occam's Razer
    Expand Collapse

    Joined:
    Aug 7, 2013
    Messages:
    1,152
    Ah, that would explain a lot. And thanks for the new code, it seems much simpler.

    However, attempting to use this in a scenario only raises a torque script error. But weirdly, it still works when manually entered into the console, which means that this line can be used by cheaters but not a content creator, which seems backward to me. This is the error message I get on the console:

    Code:
    |E|                  TS|parse error
    Not particularly helpful, unfortunately.
     
  6. Scepheo

    Scepheo
    Expand Collapse

    Joined:
    Feb 10, 2015
    Messages:
    601
    The console automatically inserts the semicolon at the end of the line if you forgot it, which is why it works there. All TS code statement should be terminated with a semicolon, which I forgot to add in the examples.
     
    • Like Like x 1
  7. Dummiesman

    Dummiesman
    Expand Collapse

    Joined:
    Sep 17, 2013
    Messages:
    4,683
    IIRC, You also need % before the object name in TS
    Code:
    TorqueScript.eval('%thePlayer.SetTransform("0 0 0 0 0 0 0");')
     
    • Like Like x 1
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice