Aller au contenu

Photo

Altering variables


  • Veuillez vous connecter pour répondre
6 réponses à ce sujet

#1
edjbooth

edjbooth
  • Members
  • 5 messages
Hi all,

I just started scripting this week and this is obviously very basic but I've spent 5 hours googling and tying to work this out and I'm getting nowhere.

Basically I'm trying to give variables a new value and it just isn't working. I want a creature to run to a waypoint when the PC gets close to it (which I have done) and then run to another point when the PC approaches again. Im using the UT_QuickMoveObject function and replacing the tag with a string variable, but after calling the function and trying to reassign the value of the variable, it doesnt change. I have confirmed this using floaty messages and tried rearranging and structuring the script many different ways.

I'm obviously missing something very basic here, is anyone able to give me a point in the right direction?

Any help much appreciated :)

#2
_L_o_B_o_

_L_o_B_o_
  • Members
  • 117 messages
Hi there,

If you could post your script (doesn't matter how ugly it looks ;) ), that would be really helpful. 

Anyway, I think that you are assuming that if you change the value of a variable in your script, the next time that script is executed, the value of the variable will be different. Am I right?

Well, that's not true. All changes that you do to variables are lost when the script ends. The only variables that keep their last value are those attached to game resources, like creatures or triggers, for example. I think that there is a project somewhere intended to allow persistent storage of values in variables, but I have never tried it.

Here are some easy solutions to your problem.

You can also use plots as storage for persistent values. You could create a plot with a flag (RUN_TO_FIRST_POINT) set and do the following in the event that triggers your NPC.

if ( WR_GetPlotFlag( MY_PLOT_NAME, RUN_TO_FIRST_POINT ) )
{   
   // Run to first point.       

   WR_SetPlotFlag( MY_PLOT_NAME, RUN_TO_FIRST_POINT, FALSE );
}
else
{   
   // Run to second point.
}

If you don't want to create a plot, you can try to use one of the local variables of your NPC. I have changed CREATURE_COUNTER_1 or CREATURE_DO_ONCE_A without any issue in my scripts, but I'm not really sure if these variables are used somewhere by the game scripts... So, I think that it is better to use the previous approach.

if ( GetLocalInt( oMyNPC, CREATURE_COUNTER_1 ) == 0 )
{   
   // Run to first point.     
  
   SetLocalInt( oMyNPC, CREATURE_COUNTER_1, 1 );
}
else
{   
   // Run to second point.
}

Modifié par _L_o_B_o_, 24 mars 2011 - 05:45 .


#3
edjbooth

edjbooth
  • Members
  • 5 messages
Ah, of course!

Thanks very much for your help Lobo! You're right, I was assuming variable changes would remain between executions. I'd seen the Get/SetLocalInt functions in my travels but it didn't quite click as to what they were for.

And yes I would have liked to post my code but the mod I'm creating is for a uni assignment so I am very hesitant to do so.

Thanks again for the pointers! :)

#4
Proleric

Proleric
  • Members
  • 2 346 messages
Here's an article on local variables.

Plot flags are great, but sometimes you need something more than a flag.

#5
edjbooth

edjbooth
  • Members
  • 5 messages
Thanks to your help, Lobo, I have learned how to use the Get/SetLocalInt functions now and my script is working as it should (almost :P).

Cheers for the link too, Proleric. It's also helped my understanding.

#6
_L_o_B_o_

_L_o_B_o_
  • Members
  • 117 messages
You're welcome, edjbooth. Get/SetLocalInt functions may be useful for easy tasks, but if you need a more exhaustive use of global variables, you should take a look at the unlimited variable storage project referenced at the end of Proleric's linked web page.

Modifié par _L_o_B_o_, 25 mars 2011 - 01:10 .


#7
Proleric

Proleric
  • Members
  • 2 346 messages
Good point.

Pre-defining variables in 2DA files does impose a design discipline, though, which documents everything in one place, and discourages sprawl.