using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(Rigidbody))]
public class PlayerController : MonoBehaviour {
{
private Rigidbody rb;
private float moveSpeed = 5f;
public float sprintSpeed = 10;
private float currentSpeed;
public global::System.Single MoveSpeed { get => moveSpeed; set => moveSpeed = value; }
void Start()
{
rb = GetComponent<Rigidbody>();
currentSpeed = MoveSpeed;
}
void update()
{
if (Input.GetKeyDown(KeyCode.LeftShift)) {
currentSpeed = sprintSpeed;
}
if (Input.GetKeyUp(KeyCode.LeftShift)) {
currentSpeed = MoveSpeed;
}
PerformMovement();
void PerformMovement()
if (Input.GetKey(KeyCode.W)) {
transform.Translate(Vector3.forward* currentSpeed * Time.deltaTime);
}
if (Input.GetKey(KeyCode.S)) {
transform.Translate(Vector3.back * currentSpeed * Time.deltaTime);
}
if (Input.GetKey(KeyCode.A)) {
transform.Translate (Vecctor3.left* currentSpeed * Time.deltaTime);
}
if (Input.Getkey(Keycode.D)) {
transform.Translate (Vector3.right* currentSpeed * Time.deltaTime);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(Rigidbody))]
public class PlayerController : MonoBehaviour {
{
private Rigidbody rb;
private float moveSpeed = 5f;
public float sprintSpeed = 10;
private float currentSpeed;
public global::System.Single MoveSpeed { get => moveSpeed; set => moveSpeed = value; }
void Start()
{
rb = GetComponent<Rigidbody>();
currentSpeed = MoveSpeed;
}
void update()
{
if (Input.GetKeyDown(KeyCode.LeftShift)) {
currentSpeed = sprintSpeed;
}
if (Input.GetKeyUp(KeyCode.LeftShift)) {
currentSpeed = MoveSpeed;
}
PerformMovement();
void PerformMovement()
if (Input.GetKey(KeyCode.W)) {
transform.Translate(Vector3.forward* currentSpeed * Time.deltaTime);
}
if (Input.GetKey(KeyCode.S)) {
transform.Translate(Vector3.back * currentSpeed * Time.deltaTime);
}
if (Input.GetKey(KeyCode.A)) {
transform.Translate (Vecctor3.left* currentSpeed * Time.deltaTime);
}
if (Input.Getkey(Keycode.D)) {
transform.Translate (Vector3.right* currentSpeed * Time.deltaTime);
}
} Nu stiu dece acceasta comanda nu mere , ma refer ce script e gresit , ma puteti ajuta sa faceti corect scriptu . Daca lai facut corect trimitetimi mail cu scriptu corect la maniurobert4@gmail.com
Hi everybody,
I spent some time this morning experimenting with ChaiScript, and wrote this basic example:
#include <memory>
#include <string>
#include <unordered_map>
#include <chaiscript/chaiscript.hpp>
class Interface final
{
public:
void setAttr(const std::string& key, const std::string& value) {
m_attributes[key] = value;
}
const std::string& getAttr(const std::string& key) {
return m_attributes[key];
}
private:
std::unordered_map<std::string, std::string> m_attributes;
};
void execute(Interface& interface, const std::string& script)
{
chaiscript::ChaiScript chai;
// Add types.
chaiscript::ModulePtr m(std::make_unique<chaiscript::Module>());
chaiscript::utility::add_class<Interface>(*m,
"Interface",
{},
{{chaiscript::fun(&Interface::setAttr), "setAttr"},
{chaiscript::fun(&Interface::getAttr), "getAttr"}}
);
chai.add(m);
// Bind global variables.
chai.add(chaiscript::var(&interface), "interface");
// Parse and run the script.
chai.eval_file(script);
}
int main(int argc, const char* argv[])
{
if (argc <= 1) { return -1; }
Interface interface;
const std::string script = argv[1];
execute(interface, script);
return 0;
}
It surprised me how easy it was to get it working.
So, here is the question. I would like to invoke the execute()
function many times, with different Interface
objects, but with the same script program. Ideally, I'd like to reuse the same chaiscript::ChaiScript chai
instance to avoid parsing/interpreting the program each time. Is this possible at the moment with ChaiScript?
Thanks!
eval_file()
(or eval()
, or the operator()
) can be evaluated several times. That is probably the answer to my previous question. A function execute()
in ChaiScript can be defined with eval_file()
, and then the function can be invoked several times, with different arguments, with chai("execute(interface);");