Giter VIP home page Giter VIP logo

Comments (8)

x87 avatar x87 commented on June 27, 2024

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.

OrhanNasuf avatar OrhanNasuf commented on June 27, 2024

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:

test-write-gvar-to-ini

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.

x87 avatar x87 commented on June 27, 2024

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.

OrhanNasuf avatar OrhanNasuf commented on June 27, 2024

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.

x87 avatar x87 commented on June 27, 2024

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.

x87 avatar x87 commented on June 27, 2024

ONMISSION = 0
image

ONMISSION = 1
image

from cleo-redux.

JuniorDjjr avatar JuniorDjjr commented on June 27, 2024

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.

x87 avatar x87 commented on June 27, 2024

Available with scm.ts

from cleo-redux.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.