Comments (8)
Using global variables in CLEO scripts is a bad practice and source of many issues. How can you guarantee correct results on a modified main.scm where global variables have different ids?
from cleo-redux.
Using global variables in CLEO scripts is a bad practice and source of many issues. How can you guarantee correct results on a modified main.scm where global variables have different ids?
While I understand that dealing with global variables is a bad practice in any context, it is what Rockstar decided to do, and it is the only way to check whether a specific mission has been passed or not.
Some use cases include rewarding the player for passing a specific mission, activating a feature only after a certain amount of progress or displaying achievements.
Based on your concern, I made a test with CLEO 2.0.0.6 on GTA 3:
{$CLEO .cs}
{$USE ini}
wait 500
write_int_to_ini_file $FLAG_JOEY_MISSION1_PASSED "CLEO\test.ini" "MISSIONS_PASSED" "JOEY_1" // Exists
write_int_to_ini_file $THIS_DOES_NOT_EXIST "CLEO\test.ini" "TEST_SECTION" "NOT_EXIST" // Does not exist
terminate_this_script
This was the result:
So it seems that either 0 is returned when accessing a global var that doesn't exist, or IniFile.WriteInt() is doing some magic.
Either way it wouldn't cause a conflict with a modified main script if handled correctly.
Perhaps a function in CLEO-Redux could do something similar, but return undefined or -1 for non-existent vars.
I tried to work around this limit by writing the values to an ini file with CLEO, which I was then going to access in my javascript with CLEO-Redux; but the File and ini plugins break when CLEO-Redux is loaded, and they cannot be used.
Is this a known issue?
from cleo-redux.
File and ini plugins break when CLEO-Redux is loaded
those plugins will only work if original CLEO 2.0.0.6 is present in the same directory
https://github.com/cleolibrary/CLEO-Redux#running-cleo-redux-as-an-addon-to-cleo-library
So it seems that either 0 is returned when accessing a global var that doesn't exist, or IniFile.WriteInt() is doing some magic.
most likely $THIS_DOES_NOT_EXIST was compiled to the first free id (one that is not declared in CustomVariables.ini) and all free variables get initialized to 0 by the default.
Some use cases include rewarding the player for passing a specific mission, activating a feature only after a certain amount of progress or displaying achievements.
Right, also someone mentioned on Discord that usage of timer/counter opcodes require a global variable. I will look into what we can do here.
from cleo-redux.
those plugins will only work if original CLEO 2.0.0.6 is present in the same directory https://github.com/cleolibrary/CLEO-Redux#running-cleo-redux-as-an-addon-to-cleo-library
Thank you!
The .cs script is now able to write the values without issue, but the game still crashes when attempting to read in javascript.
from cleo-redux.
Script that reads from and writes to the global SCM variable from JS code:
https://github.com/cleolibrary/CLEO-Redux/blob/master/examples/scm.js
Download scm.js
and place it to CLEO_PLUGINS folder. Then import readScmVariable
or writeScmVariable
in your script.
Example script that displays $ONMISSION variable on screen. To change the var value use writeScmVariable(id, value)
import { readScmVariable, writeScmVariable } from "./cleo_plugins/scm";
// get variable offset for the current game
const ONMISSION_ID = getOnMissionId();
// display the variable value on screen
while (true) {
wait(250);
FxtStore.insert("scm_var", readScmVariable(ONMISSION_ID).toString());
Text.PrintNow("scm_var", 500, 1);
}
// $ONMISSION var has different id in each game
function getOnMissionId() {
switch (GAME) {
case "re3":
case "gta3":
case "gta3_unreal":
return 207;
case "reVC":
case "vc":
case "vc_unreal":
return 313;
case "sa":
case "sa_unreal":
return 409;
}
throw new Error("Unsupported game");
}
from cleo-redux.
from cleo-redux.
Right, also someone mentioned on Discord that usage of timer/counter opcodes require a global variable. I will look into what we can do here.
In CLEO+ I created the opcodes for the local variable, it was pretty easy btw (internally, the game uses a pointer). I think this is important to add it natively in CLEO Redux.
https://github.com/JuniorDjjr/CLEOPlus/blob/main/CLEOPlus/Timer.cpp
Global variables have always been bad practice, and now it's worse as a game patch can change their id (rare, but still), plus this problem that every game is an id, you have to search for ids etc. There are also more common cases, like using an available global variable, and in a patch it is no longer available, or another script uses too etc...
Some use cases include rewarding the player for passing a specific mission, activating a feature only after a certain amount of progress or displaying achievements.
Remember that there are some stats that help with this, and it's a much better practice, some of them count how many missions of certain character has passed, or a certain mission has been completed, or how many cities have been unlocked etc. It doesn't solve all cases, but most of it (some more important). That is, before using global variable, make sure you need to use.
from cleo-redux.
Available with scm.ts
from cleo-redux.
Related Issues (20)
- CLEO commands with multiple outputs don't work correctly HOT 2
- [Bully] `Clothing.BuildPlayer()` crashes the game HOT 1
- support "long strings" in III and VC if CLEO library is present HOT 1
- GTA 3 Definitive Edition car spawning freeze HOT 4
- GTA VC Definitive Edition CRASHES
- Dispatching an event from another event crashes the game? HOT 1
- Is it possible to restore the original music using CLEO Redux in San Andreas Definitive Edition
- [STEAM] GTA Trilogy - Error Cleo Redux is and Ultimate ASI Loader HOT 2
- [Classic: San Andreas] - Events.cleo Plugin Conflict with VehFuncs HOT 14
- Incompatible with new GTA Vice City DE patch 1.0.17.39540 HOT 2
- [RGL] 1.1.2 Crashes San Andreas Definitive Edition when loading a Save. HOT 8
- CLEO Redux doesn't work for ReVC OpenGL x64 build and Re3 OpenGL x64 build HOT 1
- Raknet HOT 1
- Heli.Create should return type Heli HOT 3
- Type "label" in opcodes input HOT 1
- stack trace is wrong in typescript files
- fxt support in VC: DE HOT 1
- conversion error in Memory.Fn.ThiscallU8 HOT 2
- Fx.DrawCorona bug HOT 4
- Text operations bug in 1.2.1 HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cleo-redux.