johnnylump Posted February 23, 2013 Share Posted February 23, 2013 (edited) I have some code that includes a rand (a7) call in a rescripted function that's causing an in-game crash when it is called. This does not crash on startup, only when it is called, so it is not a virtual size, jump or parameter issue. This code works just fine (it just doesn't do what I want):07 8c 00 99 38 3a 00 6d 43 00 00 38 3a 24 0a 16 04 28 // End: 0x8cif (eUFO >= 10){ return false;} But replacing that with either of these codes cause the in-game crash: 07 8c 00 99 38 3a 00 6d 43 00 00 38 3a a7 24 0a 16 16 04 2807 8c 00 99 38 3a 00 6d 43 00 00 38 3a a7 2c 0a 16 16 04 28 // End: 0x8cif (eUFO >= Rand (10)){ return false;} UEExplorer shows no problem. The difference in size of the statements is covered by 0b (nulls), so shouldn't be a problem there. (Context: I'm trying to modify XGStrategyAI.ShouldHunt to randomize when UFOs are launched to hunt for satellites. eUFO is a function parameter refers to the class of UFO that just "got away" and wasn't intercepted properly. This function would set the chance of a satellite hunter being launched against the type of UFO, with bigger UFOs (higher eUFO number) presenting a larger chance.) Any idea what I'm doing wrong? I've seen 99 (>=) and a7 (rand) used together in if comparison statements before, so I'm a little flummoxed. Is there any limitations on the use of a7 that anyone has encountered? Edited February 23, 2013 by johnnylump Link to comment Share on other sites More sharing options...
bokauk Posted February 24, 2013 Share Posted February 24, 2013 eUFO is not declared as an int and so you cannot use the >= operator with it as it is. You'll want to cast it as an int :) Link to comment Share on other sites More sharing options...
johnnylump Posted February 24, 2013 Author Share Posted February 24, 2013 That was the clue I needed, thanks. The 3a 38 (ByteToInt PrimitiveCast) was already in there before the eUFO reference. I mistakenly assumed it was part of the variable id, and it was left before the Rand call. Removed the second 3a 38 and crashing problem is gone. Working code:07 8c 00 99 38 3a 00 6d 43 00 00 a7 2c 0a 16 16 04 28 I've said it before: Yours is the superior intellect. Link to comment Share on other sites More sharing options...
bokauk Posted February 24, 2013 Share Posted February 24, 2013 Not superior intellect at all. I've come across a similar problem before, so learnt from the mistake too :smile: Glad you got it working :smile: Link to comment Share on other sites More sharing options...
Recommended Posts