Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ChiaScript "enviroment"??? #587

Open
nanoasp opened this issue Nov 23, 2021 · 2 comments
Open

ChiaScript "enviroment"??? #587

nanoasp opened this issue Nov 23, 2021 · 2 comments

Comments

@nanoasp
Copy link

nanoasp commented Nov 23, 2021

Hi i am using ChiaScript for game development and i have used lua in my previous projects.

while using ChiaScript i am facing an issue where functions of the same names are being redefined.

this is an issue when i have multiple game objects with a script component with an update function for example.

Currently everytime i attach a new script to the Chia script it overwrite the previous and local variables are lost.
I would need different game objects to run different scripts so ....

lua has a environment where scripts can be run so this issue does not happen.
does ChiaScript have something similar?

or do i have to have a ChiaScript for each game object which is what i probably will try next.

chaiscript::ChaiScript chai;
std::vector mgameObjects;

chai.use("Assets/Scripts/registervar.chai");

mgameObjects->?????

@totalgee
Copy link
Contributor

I don't understand your incomplete example; it doesn't seem related to the description of the problem you give earlier.

What does "registervar.chai" contain? Do you mean that the C++ vector mgameObjects is being trashed by running the Chai script? (that obviously shouldn't happen)

Can you provide a small example that shows what you're actually trying to do, on the C++ and ChaiScript sides?

@nanoasp
Copy link
Author

nanoasp commented Nov 24, 2021

lets say i have 3 game objects.

  1. player
  2. destructible that spawns an object when destroyed.
  3. a turret that points towards player when player is near and start shooting.

i have made 3 different .chia scripts with the 3 different behaviours.

The main question now is how do i link and run the 3 different scripts in runtime that applies their code to 3 different objects.

gameobject{
//gameplaystuff

std::string script = "name of chia script that will be loaded.chia";
}

//list of game objects
std::vector mgameObjects;

gameloop{
std::vector mgameObjects;

//start simulation
start(){
// links gameobjects to chia scripts can calls start.function declared in chia file
for(auto go in mgameObjects){
chai.use(go.script );

}
}
}

//on every frame of simulation
update(){
//Runs chia file linked to game objects.
for(auto go in mgameObjects){
chai.eval_file(go.scripts);

}
}
}

the problem is in the linking i guess?
there is no issue with mgameObjects being trashed.
the content in the chiascripts i am loading is not the issue.
This is an architecture kinda question.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants