Quantcast

Jump to content

» «
Photo

[SA] Global Variables Question

3 replies to this topic
DeeZire
  • DeeZire

    Modder

  • Members
  • Joined: 22 Jun 2005

#1

Posted 25 November 2007 - 06:00 PM Edited by DeeZire, 25 November 2007 - 06:05 PM.

Been looking at the use of global variables in my mod, and a couple of questions arise - hoping Seeman can help with this one.

1 - can the 'useless' global variables (those only declared once and/or never used in main.scm) be re-used by me in my own scripts and threads? Is there any consequence of doing so?

2 - is there a practical limit to the amount of memory I can use with the DEFINE MEMORY command at the start of main.scm? Should I be aware of any limitations on its use, or is there a practical limit for it?

The reason Im asking is that in my mod I have declared and used quite a few globals, so I thought Id make use of some of the 'useless' ones (Ive been very careful around this, making sure they are actually not used anywhere else). I have not personally encountered any problems with doing so and have played the game without any issues. However, my mod is now in final BETA and testers are reporting crashes and issues when loading save games with my mod and Im wondering if this could be a possible cause.

Is it possible that, even though some of those globals are not used, the game exe itself still uses their values by conducting tests or checks against them with direct memory access?

Hope somebody can shed some light on it for me, many thanks!

ceedj
  • ceedj

    PEDS Creator

  • Members
  • Joined: 21 May 2005

#2

Posted 25 November 2007 - 07:18 PM Edited by ceedj, 25 November 2007 - 07:23 PM.

I can answer 1 - yes, you can use "once used" globals. The only issue you might have is that if a user loads a save game and starts a mission that uses one of the globals.

EDIT: I had this same problem with my hook; because I always tested with a completed game (all main missions done), I wouldn't get the same crashes (if at all) that others would.

Seemann
  • Seemann

    Ruhe

  • Members
  • Joined: 03 Sep 2004
  • Russia

#3

Posted 28 November 2007 - 08:56 AM

QUOTE (DeeZire @ Nov 26 2007, 02:00)
Is it possible that, even though some of those globals are not used, the game exe itself still uses their values by conducting tests or checks against them with direct memory access?

No, the exe doesn't use the global variables in any manner. They are all controlled by the scripts (main.scm and script.img). There're no hardcoded things in the exe that depends on the main.scm content.

QUOTE (DeeZire @ Nov 26 2007, 02:00)
2 - is there a practical limit to the amount of memory I can use with the DEFINE MEMORY command at the start of main.scm? Should I be aware of any limitations on its use, or is there a practical limit for it?

The higher global variable ever is $16383 as their ids is only 2 bytes in length ((16383+1)*4=65536 is maximum for unsigned 16-bit values). So, the varblock space size in the beginning of the main.scm may only be in ranges of 0 to 65536 bytes to keep the variables values in run-time. Actual size depends on the higher global variable ID (if you're using the variable $10000, the size of varspace is 40k bytes).

And yes, the 'useless' variables can be reused.

DeeZire
  • DeeZire

    Modder

  • Members
  • Joined: 22 Jun 2005

#4

Posted 28 November 2007 - 10:08 AM

Thanks guys, appreciate the info smile.gif




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users