Why is this "Set variable or attribute" thing not working properly... [SOLVED]

So, this is the issue:

player.manifestname = 1 or 2

And for some unknown reason, it becomes 3.
It makes no sense to me, could someone give me lesson about what the OR means?

Same happens if I try 2 or 3, the result will be 5. It´s like the or is just another +.

Isn´t "or" meant to work differently?


It is doing a bitwise OR. I had not realised Quest did that.
In binary, 1 is 0001 and 2 is 0010. When you OR them, every bit that is set in either number is set in the result, so 0011, which is 3 in base 10.
2 OR 3 give 3, because 0010 OR 0011 = 0011.

What are you trying to do?


I am trying to have a function like GetRandomInt.
But to do in such a way that it returns a string and I hoped that this would do but I have to find other way. (I know it´s integer)

It is difficult to explain because but basically I need {random:anything:anything2} BUT only works for first time.

So if it decides for anything2 then it will always show anything and never the other stuff...

It is just part of something I am trying to do, sorry for being vague but my code is constantly changing and I sort of forgot where was I heading with this.

EDIT: Well it would be better if I asked this question.
Is it possible to give an attribute INTEGER and STRING at the same time?


something like this?

firsttime {
  string_variable = ToString (GetRandomInt (0,9)) + " is my string value"
} otherwise {
}

you can then use 'split' and/or the 'instr or revinstr/instrrev' to get at a particular part of your combined string


you you want your own algorithm for "randomly" choosing a value... then you got to create/script your own... which is probably (at least for me) probably complex and complicated to do so, coding-wise or math-wise or both, lol.


To answer the last question first, yes. Quest will have no problem with this:

game.thing = 5
game.thing = "five"

It may have problems later if it is expecting an integer, and gets a string though.

The next version of Quest will hopefully have a function that will return a random string from a list. Here is some code that will take a string, anything:anything2:anything3, and set s to one at random (you can return that in your function):

list = Split(str, ":")
s = StringListItem(list, GetRandomInt(0, ListCount(list) - 1))

I did a lot of this sort of thing in my game Deeper, as it is virtually all randomly generated. Lots of descriptions had to be random, but stay the same.

An alternative approach would be to use the built in system. Say you have the text, compled with {random:anything:anything2}, in a variable, text, then do this (which is copied from OutputText)

data = NewDictionary()
dictionary add (data, "fulltext", text)
text = ProcessTextSection(text, data)

Then instead of printing the result, set it to an attribute, and it will keep that same value.


simple if else statement should work:

pseudo code:
if player.manifestname >=X then player.manifestname==1 else player.manifestname==2


wow, bangs head, I always overthink stuff... argh! lol

(though, this would only work for binary/dualism options, I think. Err... 3 options would work too actually: if >/more, else if =/same/equal, else if </less, but I don't think for 4 or more options)


well, your example only showed the need for 2 names. So what are you actually trying to accomplish? How many names are you going to have on the manifest?

You need a placeholder name, btw, that displays when no real name is there. Something like Nobody.

Are you generating these names on the fly, or are they a set number of names that the player discovers in the game and that then show up on the manifest?


indeed, we don't know if OP/Sebastion just needs something for only 2 options (ie the '1 or 2' was a specific example) or more options/scalable (ie the '1 or 2' was just a general example), well at least I can't tell.. lol.

For directly what OP/Sebastion posted (no consideration of context -- I always over-think stuff lol), then OP/Sebastion only wants/needs something for 2 options


Thanks everyone for the willingness to help but I couldn´t use any of the advice above because I needed a system that could display as many as 1000 possible names so..

But the good thing is that I found a way, I am going to show once it´s all done.


One way to do that would be to create an attribute of, say, the game object, and set it to be a string list, and add a couple of names. Then go into full code view, and look at how Quest has formatted the names. Go to a web site that lists boys names, and grab the list, then use a decent editor (Notepad++ say) to do fin-and-replace to format all the names in the Quest way, and then insert that into your game. Do the same for girls names (I recommend doing them separately, as this is likely to be significant somewhere along the way).


Hmm, that will probably save me a lot of time. Thanks!


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums